load->model('ProjectsModel', '', TRUE); $this->load->model('FileModel', '', TRUE); } public function index() { $this->neededPermission('projects.view'); $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) { $this->neededPermission('projects.create'); $edit = $id === NULL ? false : true; $content = null; $projectCategories = []; if ($edit) { // TODO: Check if project is created by user or not $this->neededPermission('projects.edit'); if ($this->ProjectsModel->checkIfExists($id)) { $content = $this->ProjectsModel->getEntry($id); $content = $this->ProjectsModel->mergeFullTranslationData($content)[0]; $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']]); $this->load->view('admin/project_edit', ['edit' => $id === NULL ? -1 : $id, 'categories' => $categories, 'content' => $content, 'pCategories' => $projectCategories]); $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.']); exit; } $translations = []; $translations['de']['title'] = $this->input->post('titleDE'); $translations['de']['description'] = $this->input->post('headlineDE'); $translations['de']['content'] = $this->input->post('contentDE'); $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'); $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'); $id = filter_input(INPUT_POST, "id"); $this->ProjectsModel->delete($id); } public function delete_category() { $this->neededPermission('projects.deleteCategory'); $id = filter_input(INPUT_POST, "id"); $this->ProjectsModel->deleteCategory($id); } }