Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/application/controllers/admin/Projects.php

132 lines
5.6 KiB
PHP
Raw Normal View History

2018-10-16 16:28:42 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Projects extends MY_Controller
2018-10-16 16:28:42 +00:00
{
public function __construct()
{
parent::__construct();
$this->load->model('ProjectsModel', '', TRUE);
$this->load->model('FileModel', '', TRUE);
}
public function index()
{
$this->neededPermission('projects.view');
2018-10-16 16:28:42 +00:00
$entries = $this->ProjectsModel->getEntries('all');
$categories = $this->ProjectsModel->getCategoriesRaw('all');
2018-10-16 16:28:42 +00:00
$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)
{
$this->neededPermission('projects.create');
2018-10-16 16:28:42 +00:00
$edit = $id === NULL ? false : true;
2018-10-16 16:28:42 +00:00
$content = null;
$projectCategories = [];
if ($edit) {
// TODO: Check if project is created by user or not
$this->neededPermission('projects.edit');
2018-10-16 16:28:42 +00:00
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 (!$this->hasPermission('projects.create')) {
echo json_encode(['success' => false, 'message' => 'Du hast nicht genügend Rechte, um Projekte zu erstellen.']);
exit;
}
$editingID = $this->input->post('editingID');
// TODO: Check if user is author of project
if($editingID !== '-1' && !$this->hasPermission('projects.edit')) {
echo json_encode(['success' => false, 'message' => 'Du hast nicht genügend Rechte, um Projekte zu bearbeiten.']);
2018-10-16 16:28:42 +00:00
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');
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()
{
// TODO: Check if user is author of project
$this->neededPermission('projects.delete');
2018-10-16 16:28:42 +00:00
$id = filter_input(INPUT_POST, "id");
$this->ProjectsModel->delete($id);
}
public function delete_category()
{
$this->neededPermission('projects.deleteCategory');
2018-10-16 16:28:42 +00:00
$id = filter_input(INPUT_POST, "id");
$this->ProjectsModel->deleteCategory($id);
}
}