2018-10-16 16:28:42 +00:00
|
|
|
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Projects extends CI_Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->load->model('ProjectsModel', '', TRUE);
|
|
|
|
$this->load->model('FileModel', '', TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login'));
|
|
|
|
|
|
|
|
$entries = $this->ProjectsModel->getEntries('all');
|
|
|
|
$categories = $this->ProjectsModel->getCategories('all');
|
|
|
|
|
|
|
|
$this->load->view('admin/sidebar', ['title' => 'Projekte verwalten']);
|
|
|
|
$this->load->view('admin/projects', ['entries' => $entries, 'categories' => $categories]);
|
|
|
|
$this->load->view('admin/footer');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit($id = NULL)
|
|
|
|
{
|
|
|
|
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login'));
|
|
|
|
$edit = $id === NULL ? false : true;
|
|
|
|
$content = null;
|
|
|
|
$projectCategories = [];
|
|
|
|
|
|
|
|
if ($edit) {
|
|
|
|
if ($this->ProjectsModel->checkIfExists($id)) {
|
2018-10-27 10:08:54 +00:00
|
|
|
$content = $this->ProjectsModel->getEntry($id);
|
|
|
|
$content = $this->ProjectsModel->mergeFullTranslationData($content)[0];
|
2018-10-16 16:28:42 +00:00
|
|
|
$projectCategories = $this->ProjectsModel->getEntryCategories($id);
|
|
|
|
} else {
|
|
|
|
redirect(base_url('admin/projects/edit'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$categories = $this->ProjectsModel->getCategories();
|
|
|
|
|
|
|
|
$this->load->view('admin/sidebar', ['title' => 'Projekt erstellen', 'additionalStyles' => ['lib/content-tools/content-tools.min.css', 'project-edit.css']]);
|
2018-10-27 10:08:54 +00:00
|
|
|
$this->load->view('admin/project_edit', ['edit' => $id === NULL ? -1 : $id, 'categories' => $categories, 'content' => $content, 'pCategories' => $projectCategories]);
|
2018-10-16 16:28:42 +00:00
|
|
|
$this->load->view('admin/footer', ['additionalScripts' => ['lib/content-tools/content-tools.min.js', 'project-edit.js']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sendEdit()
|
|
|
|
{
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) {
|
|
|
|
echo json_encode(['success' => false, 'message' => 'Du hast nicht genügend Rechte, um Projekte zu erstellen bzw. bearbeiten.']);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$translations = [];
|
|
|
|
$translations['de']['title'] = $this->input->post('titleDE');
|
|
|
|
$translations['de']['description'] = $this->input->post('headlineDE');
|
|
|
|
$translations['de']['content'] = $this->input->post('contentDE');
|
2018-10-27 10:08:54 +00:00
|
|
|
$translations['en']['title'] = $this->input->post('titleEN');
|
|
|
|
$translations['en']['description'] = $this->input->post('headlineEN');
|
|
|
|
$translations['en']['content'] = $this->input->post('contentEN');
|
|
|
|
$translations['fr']['title'] = $this->input->post('titleFR');
|
|
|
|
$translations['fr']['description'] = $this->input->post('headlineFR');
|
|
|
|
$translations['fr']['content'] = $this->input->post('contentFR');
|
2018-10-16 16:28:42 +00:00
|
|
|
|
|
|
|
$url = $this->input->post('url');
|
|
|
|
|
|
|
|
$download['available'] = $this->input->post('isDownloadable') == 'on' ? true : false;
|
|
|
|
$download['link'] = $this->input->post('downloadLink');
|
|
|
|
$download['name'] = $this->input->post('downloadLinkName');
|
|
|
|
|
|
|
|
$openSource['available'] = $this->input->post('isOpenSource') == 'on' ? true : false;
|
|
|
|
$openSource['link'] = $this->input->post('openSourceLink');
|
|
|
|
$openSource['name'] = $this->input->post('openSourceLinkName');
|
|
|
|
|
|
|
|
$customLink['link'] = $this->input->post('customLink');
|
|
|
|
$customLink['name'] = $this->input->post('customLinkName');
|
|
|
|
|
|
|
|
$categories = $this->input->post('categories');
|
|
|
|
$date = date('Y-m-d H:i:s', strtotime($this->input->post('date')));
|
|
|
|
$image = $this->input->post('image');
|
|
|
|
|
|
|
|
$editingID = $this->input->post('editingID');
|
|
|
|
|
|
|
|
if($editingID == '-1' && $this->ProjectsModel->checkIfNameExists($url)) {
|
|
|
|
echo json_encode(['success' => false, 'message' => 'Die angegebene URL ist bereits vergeben.']);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($editingID == '-1' || !$this->ProjectsModel->checkIfExists($editingID)) {
|
|
|
|
$editingID = $this->ProjectsModel->createNewProjectDraft();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->ProjectsModel->updateProject($editingID, $translations, $url, $download, $openSource, $customLink, $date, $image);
|
|
|
|
$this->ProjectsModel->updateCategories($editingID, $categories);
|
|
|
|
|
|
|
|
echo json_encode(['success' => true, 'message' => 'Das Projekt wurde erfolgreich gespeichert.', 'id' => $editingID]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login'));
|
|
|
|
$id = filter_input(INPUT_POST, "id");
|
|
|
|
$this->ProjectsModel->delete($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete_category()
|
|
|
|
{
|
|
|
|
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login'));
|
|
|
|
$id = filter_input(INPUT_POST, "id");
|
|
|
|
$this->ProjectsModel->deleteCategory($id);
|
|
|
|
}
|
|
|
|
}
|