File indexing completed on 2024-12-22 05:33:27
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class Backend_SliderController extends Local_Controller_Action_Backend 0024 { 0025 0026 protected $_table; 0027 0028 public function init() 0029 { 0030 $this->_table = new Default_Model_DbTable_ContentSlider(); 0031 parent::init(); 0032 } 0033 0034 public function indexAction() 0035 { 0036 0037 $sel = $this->_table->select(); 0038 0039 $sel->where('is_deleted=0')->order('order_pos'); 0040 0041 $this->view->sliderImages = $this->_table->fetchAll($sel); 0042 } 0043 0044 public function addAction() 0045 { 0046 0047 if ($this->_request->isPost()) { 0048 $form = $this->getForm(); 0049 0050 if ($form->isValid($_POST)) { 0051 0052 $values = $form->getValues(); 0053 0054 if ($values['picture']) { 0055 0056 $newVals = array( 0057 'image' => $values['picture'], 0058 'order_pos' => $values['order_pos'], 0059 'created_at' => new Zend_Db_Expr("NOW()"), 0060 'changed_at' => new Zend_Db_Expr("NOW()") 0061 0062 ); 0063 0064 $this->_table->insert($newVals); 0065 0066 $this->view->saveText = "Bild gespeichert!"; 0067 } else { 0068 $this->view->saveText = "Da kein Bild hochgeladen wurde, wurde auch nichts gespeichert."; 0069 } 0070 } else { 0071 $this->view->form = $form; 0072 } 0073 } else { 0074 $this->view->form = $this->getForm(); 0075 } 0076 } 0077 0078 public function getForm($valPicture = "", $valOrderPos = "") 0079 { 0080 $form = new Zend_Form(); 0081 $form->setMethod('POST'); 0082 $form->setAttrib('enctype', 'multipart/form-data'); 0083 0084 $picture = $form->createElement('file', 'picture'); 0085 $picture->setLabel('Slider-Bild: ')->setDestination((string)Zend_Registry::get('sliderImages2'))->setMultiFile(1); 0086 0087 if ($valPicture) { 0088 $picture->setDescription('Vorhandenes Bild:<br/><img src="/images/slider2/' . $valPicture 0089 . '" border="0" height="80px" />'); 0090 } 0091 0092 $picture->getDecorator('description')->setEscape(false); 0093 0094 $pos = $form->createElement('text', 'order_pos')->setLabel("Reihenfolgenposition:")->setDescription("Nur Zahlen (1,2,3...)") 0095 ->setValue($valOrderPos) 0096 ; 0097 0098 $form->addElement($picture); 0099 $form->addElement($pos); 0100 $form->addElement('submit', 'save', array('label' => 'Speichern')); 0101 0102 return $form; 0103 } 0104 0105 public function editAction() 0106 { 0107 0108 $id = $this->getParam('id'); 0109 0110 $editImage = $this->_table->fetchRow('content_slider_id=' . $id); 0111 0112 if ($this->_request->isPost()) { 0113 0114 $form = $this->getForm(); 0115 0116 if ($form->isValid($_POST)) { 0117 0118 $values = $form->getValues(); 0119 0120 if ($values['picture']) { 0121 $editImage->image = $values['picture']; 0122 } 0123 0124 $editImage->order_pos = $values['order_pos']; 0125 0126 $editImage->save(); 0127 0128 $this->view->saveText = "Erfolgreich gespeichert."; 0129 } else { 0130 $this->view->form = $form; 0131 } 0132 } else { 0133 $this->view->form = $this->getForm($editImage->image, $editImage->order_pos); 0134 } 0135 } 0136 0137 public function setstatusAction() 0138 { 0139 $this->_helper->layout->disableLayout(); 0140 0141 $id = $this->getParam('id'); 0142 $status = $this->getParam("status"); 0143 0144 $this->_table->setStatus($status, $id); 0145 0146 $this->_helper->json(true); 0147 } 0148 0149 public function deleteAction() 0150 { 0151 $this->_helper->layout->disableLayout(); 0152 0153 $id = $this->getParam('id'); 0154 0155 $this->_table->setDelete($id); 0156 0157 $this->_helper->json(true); 0158 } 0159 0160 }