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_MailController extends Local_Controller_Action_Backend
0024 {
0025 
0026     private $_mailTplTable;
0027 
0028     public function init()
0029     {
0030         $this->_mailTplTable = new Default_Model_DbTable_MailTemplate();
0031         parent::init();
0032     }
0033 
0034     /**
0035      *
0036      * @return json projectlist
0037      */
0038     public function indexAjaxAction()
0039     {
0040         $this->_helper->layout->disableLayout();
0041 
0042         $start = $this->getParam('start', 0);
0043         $count = $this->getParam('count', 20);
0044         $sort = $this->getParam('sort', 'created_at');
0045         $dir = $this->getParam('dir');
0046         $dir = ($dir == 'yui-dt-desc') ? 'DESC' : 'ASC';
0047         $filter = $this->getParam('filter', null);
0048 
0049         $sel = $this->_mailTplTable->select()->setIntegrityCheck(false);
0050         $sel->from($this->_mailTplTable,
0051             array('mail_template_id', 'name', 'subject', 'text', 'created_at', 'changed_at'))//                ->where('is_deleted=0')
0052             ->order($sort, $dir)->limit($count, $start)
0053         ;
0054 
0055         if ($filter) {
0056             foreach ($filter as $field => $value) {
0057                 $sel->where($field . ' like "' . $value . '%"');
0058             }
0059         }
0060 
0061         $mailTplData = $this->_mailTplTable->fetchAll($sel);
0062         $mailTplData = $mailTplData->toArray();
0063 
0064         $responsData['results'] = $mailTplData;
0065         $responsData['totalRecords'] = count($mailTplData);
0066 
0067         $this->_helper->json($responsData);
0068     }
0069 
0070     public function indexAction()
0071     {
0072 
0073     }
0074 
0075     public function addAction()
0076     {
0077 
0078         if ($this->_request->isPost()) {
0079             // is Post-Request - das Formular
0080             $form = $this->getForm();
0081             if ($form->isValid($_POST)) {
0082                 //alles ok
0083                 $values = $form->getValues();
0084 
0085                 $insertValues = array(
0086                     'name'       => $values['title_intern'],
0087                     'subject'    => $values['subject'],
0088                     'text'       => $values['content'],
0089                     'created_at' => new Zend_Db_Expr('Now()'),
0090                     'changed_at' => new Zend_Db_Expr('Now()')
0091                 );
0092 
0093                 $this->_mailTplTable->insert($insertValues);
0094 
0095                 $this->view->saveText = "eMail-Template gespeichert";
0096             } else {
0097                 //fehler
0098                 $this->view->form = $form;
0099             }
0100         } else {
0101             // normaler Aufruf (GET) - kein Formular
0102             $this->view->form = $this->getForm();
0103         }
0104         $this->renderScript('mail/edit.phtml');
0105     }
0106 
0107     public function getForm($valTitleIntern = "", $valSubject = "", $valContent = "")
0108     {
0109 
0110         $form = new Zend_Form();
0111         $form->setMethod('POST');
0112 
0113         $title = $form->createElement('text', 'title_intern');
0114         $title->setLabel('Interner Name: ');
0115         $title->setValue($valTitleIntern);
0116         $title->setRequired(true);
0117 
0118         $subject = $form->createElement('text', 'subject');
0119         $subject->setLabel('Betreff: ');
0120         $subject->setValue($valSubject);
0121         $subject->setRequired(true);
0122 
0123         $content = $form->createElement('textarea', 'content');
0124         $content->setLabel('Content: ');
0125         $content->setValue($valContent);
0126         $content->setRequired(true);
0127 
0128         $form->addElement($title)->addElement($subject)->addElement($content)
0129              ->addElement('submit', 'save', array('label' => 'Speichern'))
0130         ;
0131 
0132         return $form;
0133     }
0134 
0135     public function editAction()
0136     {
0137         if ($this->_request->isPost()) {
0138             // is Post-Request - das Formular
0139             $form = $this->getForm();
0140             if ($form->isValid($_POST)) {
0141                 //alles ok
0142                 $values = $form->getValues();
0143 
0144                 $updateValues = array(
0145                     'name'       => $values['title_intern'],
0146                     'subject'    => $values['subject'],
0147                     'text'       => $values['content'],
0148                     'changed_at' => new Zend_Db_Expr('Now()')
0149                 );
0150 
0151                 $id = $this->_request->getParam('id');
0152 
0153                 $this->_mailTplTable->update($updateValues, "mail_template_id=" . $id);
0154 
0155                 $this->view->saveText = "eMail-Template gespeichert";
0156             } else {
0157                 //fehler
0158                 $this->view->form = $form;
0159             }
0160         } else {
0161             // normaler Aufruf (GET) - kein Formular
0162             $id = $this->_request->getParam('id');
0163 
0164             $editItem = $this->_mailTplTable->find($id);
0165             $editItem = $editItem[0];
0166             $this->view->form =
0167                 $this->getForm(stripslashes($editItem->name), stripslashes($editItem->subject), stripslashes($editItem->text));
0168         }
0169     }
0170 
0171     public function setstatusAction()
0172     {
0173         //        $this->_helper->layout->disableLayout();
0174         //
0175         //        $id = $this->getParam('id');
0176         //        $status = $this->getParam("status");
0177         //
0178         //        $this->_contentTable->setStatus($status,$id);
0179         //
0180         //        $this->_helper->json(true);
0181     }
0182 
0183     public function deleteAction()
0184     {
0185         //        $this->_helper->layout->disableLayout();
0186         //
0187         //        $id = $this->getParam('id');
0188         //
0189         //        $this->_contentTable->setDelete($id);
0190         //
0191         //        $this->_helper->json(true);
0192     }
0193 
0194 }