public function edit($id = null) { $this->checkLogon(); $this->setLayout('admin/admin'); $this->setTemplate('comic/edit'); //get the chapters $chapters = $this->chapterModel->getAll(); $this->set('chapters', $chapters); $this->input = $_REQUEST; $id = !empty($id) ? $id : (!empty($this->input['id']) ? $this->input['id'] : ''); $this->validation->setRules('id', 'Id', 'numeric'); $this->validation->setRules('chapter_id', 'Name', 'optional|numeric'); $this->validation->setRules('number', 'Number', 'required|numeric|check_unique[' . $this->checkUnique('number', $id) . ']'); $this->validation->setRules('title', 'Title', 'required|check_unique[' . $this->checkUnique('title', $id) . ']'); $this->validation->setRules('slug', 'Slug', 'required|slug|check_unique[' . $this->checkUnique('slug', $id) . ']'); $this->validation->setRules('date', 'Date', 'required|valid_date[m/d/Y]'); $this->validation->setRules('comment', 'Comment', 'optional|required'); if (!$this->validation->validate()) { if (empty($this->input)) { $comic = $this->comicModel->get($id); $this->set('comic', $comic); } else { $comic = $this->input; $this->set('comic', $comic); $this->set('errors', $this->validation->getErrors()); } } else { $comic = array(); $comic['id'] = $this->input['id']; $comic['slug'] = $this->input['slug']; $comic['number'] = $this->input['number']; $comic['date'] = date('Y-m-d', strtotime($this->input['date'])); $comic['comment'] = $this->input['comment']; if (!empty($this->input['chapter_id'])) { $comic['chapter_id'] = trim($this->input['chapter_id']); } else { $comic['chapter_id'] = 0; } $comic['title'] = trim($this->input['title']); if ($this->comicModel->update($comic)) { //do file upload $upload_config['upload_dir'] = 'strips'; $upload_config['max_size'] = '3000000'; $upload_config['allowed_types'] = array('jpg', 'jpeg', 'png', 'gif'); $ptyxisUpload = new PtyxisUpload($upload_config); $errors = $ptyxisUpload->uploadImage('comic_image', $comic['id']); if (!empty($errors)) { $this->set('comic', $comic); $this->set('errors', $errors); } else { //delete any extra comic images $detectedType = pathinfo($_FILES['comic_image']['name'], PATHINFO_EXTENSION); if (!empty($detectedType)) { $this->deleteComicImage($comic['id'], $detectedType); } $this->session->flashRedirect('Comic saved successfully', $this->baseUrl() . 'comics/edit/' . $comic['id']); } } else { $comic = $this->input; $this->set('comic', $comic); $errors[] = array('label' => 'Error', 'error' => 'Unable to save comic'); $this->set('errors', $errors); } } return $this->data; }
public function theme() { $this->checkLogon(); $this->setLayout('admin/admin'); $this->setTemplate('setting/theme'); $this->input = $_REQUEST; if (!empty($this->input['upload'])) { //do file upload $upload_config['upload_dir'] = 'images'; $upload_config['max_size'] = '1000000'; $upload_config['allowed_types'] = array('png'); $ptyxisUpload = new PtyxisUpload($upload_config); $logo_errors = $ptyxisUpload->uploadImage('logo', 'logo'); $upload_config['upload_dir'] = 'images'; $upload_config['max_size'] = '1000000'; $upload_config['allowed_types'] = array('png'); $ptyxisUpload = new PtyxisUpload($upload_config); $bg_errors = $ptyxisUpload->uploadImage('background', 'background'); $errors = array_merge($logo_errors, $bg_errors); if (!empty($errors)) { $this->set('errors', $errors); } else { $this->session->flashRedirect('Upload successful', $this->baseUrl() . 'dashboard'); } } return $this->data; }