Implement config & model upload for new projects
This commit is contained in:
@@ -2,29 +2,29 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Projects extends MY_Controller {
|
class Projects extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,56 +50,82 @@ class Projects extends MY_Controller {
|
|||||||
* Allows users to create a new project.
|
* Allows users to create a new project.
|
||||||
*/
|
*/
|
||||||
public function create() {
|
public function create() {
|
||||||
|
$this->load->library('upload');
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
|
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
|
||||||
|
|
||||||
$config = array(
|
$config = array(
|
||||||
array(
|
array(
|
||||||
'field' => 'name',
|
'field' => 'name',
|
||||||
'label' => 'Projektname',
|
'label' => 'Projektname',
|
||||||
'rules' => 'trim|required|min_length[3]|max_length[100]|xss_clean',
|
'rules' => 'trim|required|min_length[3]|max_length[100]|xss_clean',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'field' => 'description',
|
'field' => 'description',
|
||||||
'label' => 'Beschreibung',
|
'label' => 'Beschreibung',
|
||||||
'rules' => 'trim|required|xss_clean',
|
'rules' => 'trim|required|xss_clean',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'field' => 'defaultmodel',
|
'field' => 'defaultmodel',
|
||||||
'label' => '3D-Modell',
|
'label' => '3D-Modell',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'field' => 'defaultconfig',
|
'field' => 'defaultconfig',
|
||||||
'label' => 'Standard-Konfiguration',
|
'label' => 'Standard-Konfiguration',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->form_validation->set_rules($config);
|
$this->form_validation->set_rules($config);
|
||||||
|
|
||||||
|
$config = array();
|
||||||
|
$config['upload_path'] = '/tmp';
|
||||||
|
$config['allowed_types'] = 'zip';
|
||||||
|
$config['max_size'] = '1024';
|
||||||
|
$config['file_name'] = 'defaultmodel';
|
||||||
|
|
||||||
if ($this->form_validation->run() == FALSE) {
|
$this->upload->initialize($config);
|
||||||
$this->load->view('project/new');
|
$modelUploaded = $this->upload->do_upload('defaultmodel');
|
||||||
|
$modelData = $this->upload->data();
|
||||||
|
|
||||||
|
$config['file_name'] = 'defaultconfig';
|
||||||
|
|
||||||
|
$this->upload->initialize($config);
|
||||||
|
$configUploaded = $this->upload->do_upload('defaultconfig');
|
||||||
|
$configData = $this->upload->data();
|
||||||
|
|
||||||
|
// run form validation
|
||||||
|
if ($this->form_validation->run() == false || $modelUploaded == false || $configUploaded == false) {
|
||||||
|
$data['model']['success'] = $modelUploaded;
|
||||||
|
$data['config']['success'] = $configUploaded;
|
||||||
|
|
||||||
|
$this->load->view('project/new', $data);
|
||||||
} else {
|
} else {
|
||||||
// TODO: handle file upload
|
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'name' => $this->input->post('name'),
|
'name' => $this->input->post('name'),
|
||||||
'description' => $this->input->post('description'),
|
'description' => $this->input->post('description'),
|
||||||
'defaultmodel' => "todo",
|
'defaultmodel' => $modelData['file_name'],
|
||||||
'defaultconfig' => "todo",
|
'defaultconfig' => $configData['file_name'],
|
||||||
);
|
);
|
||||||
|
|
||||||
$data['project_id'] = $this->project->create($data);
|
$data['project_id'] = $this->project->create($data);
|
||||||
if ($data['project_id']) {
|
|
||||||
|
if (isset($data['project_id'])) {
|
||||||
$userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/';
|
$userpath = FCPATH . 'uploads/' . $this->session->userdata('user_id') . '/';
|
||||||
$projectpath = $userpath . $data['project_id'] . '/';
|
$projectpath = $userpath . $data['project_id'] . '/';
|
||||||
if (!is_dir($projectpath))
|
|
||||||
if(!is_dir($userpath))
|
if (!is_dir($projectpath)) {
|
||||||
|
if (!is_dir($userpath)) {
|
||||||
mkdir($userpath, 0777);
|
mkdir($userpath, 0777);
|
||||||
|
chmod($userpath, 0777);
|
||||||
|
}
|
||||||
mkdir($projectpath, 0777);
|
mkdir($projectpath, 0777);
|
||||||
chmod($userpath, 0777);
|
chmod($projectpath, 0777);
|
||||||
chmod($projectpath, 0777);
|
}
|
||||||
$this->messages->add($projectpath, 'notice');
|
|
||||||
|
copy($modelData['full_path'], $projectpath . $modelData['file_name']);
|
||||||
|
copy($configData['full_path'], $projectpath . $configData['file_name']);
|
||||||
|
|
||||||
|
$this->messages->add($projectpath, 'notice');
|
||||||
redirect('/projects/detail/' . $data['project_id'], 301);
|
redirect('/projects/detail/' . $data['project_id'], 301);
|
||||||
} else {
|
} else {
|
||||||
$this->messages->add('Das Projekt konnte nicht gespeichert werden.', 'error');
|
$this->messages->add('Das Projekt konnte nicht gespeichert werden.', 'error');
|
||||||
@@ -132,7 +158,7 @@ class Projects extends MY_Controller {
|
|||||||
/**
|
/**
|
||||||
* Allows users to delete a project.
|
* Allows users to delete a project.
|
||||||
*
|
*
|
||||||
* @param unknown_type $projectId
|
* @param integer $projectId
|
||||||
*/
|
*/
|
||||||
public function delete($projectId) {
|
public function delete($projectId) {
|
||||||
$this->project->delete($projectId);
|
$this->project->delete($projectId);
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
<div class="box">
|
<div class="box">
|
||||||
|
|
||||||
|
|
||||||
<form method="post" name="createproject" action="<?=site_url('projects/create')?>">
|
<form method="post" name="createproject" action="<?=site_url('projects/create')?>" enctype="multipart/form-data">
|
||||||
<h3>Erforderliche Angaben zum Projekt</h3>
|
<h3>Erforderliche Angaben zum Projekt</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<h4>Projektname <span class="req">*</span></h4>
|
<h4>Projektname <span class="req">*</span></h4>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="name" class="short text" tabindex="1" value="<?=set_value('name')?>">
|
<input type="text" name="name" class="short text" tabindex="1" value="<?=set_value('name') == null ? $this->input->post('name') : set_value('name');?>">
|
||||||
<?=form_error('name')?>
|
<?=form_error('name')?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<h4>Beschreibung</h4>
|
<h4>Beschreibung</h4>
|
||||||
<label class="note">Eine Beschreibung ist hilfreich, wenn Sie dieses Projekt später für andere Mitarbeiter freigeben möchten.</label>
|
<label class="note">Eine Beschreibung ist hilfreich, wenn Sie dieses Projekt später für andere Mitarbeiter freigeben möchten.</label>
|
||||||
<div>
|
<div>
|
||||||
<textarea name="description" rows="6" cols="60" tabindex="2" class="textarea"><?=set_value('description')?></textarea>
|
<textarea name="description" rows="6" cols="60" tabindex="2" class="textarea"><?=set_value('description') == null ? $this->input->post('description') : set_value('description');?></textarea>
|
||||||
<?=form_error('description')?>
|
<?=form_error('description')?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
Es kann weiterhin bei jedem Versuch ein anderes Modell gewählt werden.</label>
|
Es kann weiterhin bei jedem Versuch ein anderes Modell gewählt werden.</label>
|
||||||
<div>
|
<div>
|
||||||
<input type="file" class="file" name="defaultmodel" tabindex="3" value="<?=set_value('defaultmodel')?>">
|
<input type="file" class="file" name="defaultmodel" tabindex="3" value="<?=set_value('defaultmodel')?>">
|
||||||
<?=form_error('defaultmodel')?>
|
<?=$model['success'] ? '' : $this->upload->display_errors('<span class="error">', '</span>');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
Diese Konfiguration kann bei jedem Versuch geändert werden.</label>
|
Diese Konfiguration kann bei jedem Versuch geändert werden.</label>
|
||||||
<div>
|
<div>
|
||||||
<input type="file" class="file" name="defaultconfig" tabindex="4" value="<?=set_value('defaultconfig')?>">
|
<input type="file" class="file" name="defaultconfig" tabindex="4" value="<?=set_value('defaultconfig')?>">
|
||||||
<?=form_error('defaultconfig')?>
|
<?=$config['success'] ? '' : $this->upload->display_errors('<span class="error">', '</span>');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
Reference in New Issue
Block a user