Form.php 7.56 KB
<?php
/**
 * @package  anc_text 
 * @category magento
 * @mailto	code [at] netz.coop
 * @author	netz.coop eG* 
 * @copyright (c) 2014, netz.coop eG
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */ 


class Anc_Text_Block_Adminhtml_Texts_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {

	protected function _prepareForm() {
		$admin_id = Mage::getSingleton('admin/session')->getUser()->getId();
		if (Mage::registry('anc_text')) {
			$data = Mage::registry('anc_text')->getData();
		} else {
			$data = array();
		}
		if (strpos($data['path'], "/media/") === 0) {
			$data['path'] = substr($data['path'], 7);
			$data['path'] = dirname($data['path']) . '/';
		}
		$varParam = $this->getRequest()->getParams();
//		D::s($data,'data',5,1,1);



		$form = new Varien_Data_Form(array(
			'id' => 'edit_form',
			'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
			'method' => 'post',
			'enctype' => 'multipart/form-data'
		));
		$this->setForm($form);
		$fieldset = $form->addFieldset('anc_text', array('name' => 'name')); //Mage::helper('news')->__('news information')));
//		D::s($data,'$data',5,1,1);

		if ($data['path'] && $data['file']) {
//			echo '<img src="' . $data['path'] . $data['file'] . '" alt = "' . $data['file'] . '" />';
		}


		$fieldset->addField('name', 'text', array(
			'label' => Mage::helper('anc_text/data')->__('Name'),
//			'class' => 'required-entry',
			'required' => false,
			'name' => 'name',
		));

		$fieldset->addField('comment', 'textarea', array(
			'label' => Mage::helper('anc_text/data')->__('Comment'),
//			'class' => 'required-entry',
			'required' => false,
			'name' => 'comment',
		));
		
		$fieldset->addField('content', 'textarea', array(
			'label' => Mage::helper('anc_text/data')->__('Text'),
//			'class' => 'required-entry',
			'required' => false,
			'name' => 'content',
		));

		if ($varParam['kind'] === 'users' || $data['customer_id'] > 0) {
			$fieldset->addField('customer_id', 'text', array(
				'label' => Mage::helper('anc_album/data')->__('Customer Id'),
				'class' => 'required-entry',
				'required' => true,
				'name' => 'customer_id',
			));
		}



//		$fieldset->addField('path', 'text', array(
//			'label' => Mage::helper('anc_text/data')->__('Pfad'),
//			'value' => 'anc/text/admin/' . $admin_id . '/original/',
//			'class' => 'required-entry',
//			'required' => true,
//			'name' => 'path',
//		));


//		$fieldset->addField('file', 'text', array(
//			'label' => Mage::helper('anc_text/data')->__('Datei'),
//			'class' => 'required-entry',
//			'required' => true,
//			'name' => 'file',
//		));



		$array = Mage::helper('anc_lib/sql')->selectFetchAll(
				'anc_album_ncalbum');
//		D::s($array,'$array',5,1,1);
		$arrayoptions = array('-1' => 'Bitte wählen..');
		foreach ($array as $key => $value) {
			$arrayoptions[$value['entity_id']] = $value['name'];
		}
//		$testarray=array('-1'=>'Please Select..','1' => 'Option1','2' => 'Option2', '3' => 'Option3');
//		D::s($arrayoptions,'$array',5,1,1);
//		D::s($testarray,'$testarray',5,1,1);
//		$varParam = $this->getRequest()->getParams();
		if (array_key_exists('albumid', $varParam)) {
			$var_album_id = $varParam['albumid'];
		}

		$fieldset->addField('ncalbum_id', 'select', array(
			'label' => Mage::helper('anc_album/data')->__('Album'),
			'class' => 'required-entry',
			'required' => true,
			'name' => 'ncalbum_id',
			'onclick' => "",
			'onchange' => "",
			'value' => $var_album_id,
			'values' => $arrayoptions,
			'disabled' => false,
			'readonly' => false,
		));
		
		
		
//		$arrayoptionsViG=array(
//			0 => 'Nein',
//			1=>'Ja'
//		);
//		
//		$fieldset->addField('visibleingallery', 'select', array(
//			'label' => Mage::helper('anc_album/data')->__('Sichtbar in Galerie'),
//			'class' => 'required-entry',
//			'required' => true,
//			'name' => 'visibleingallery',
//			'onclick' => "",
//			'onchange' => "",
//			'value' => 1,
//			'values' => $arrayoptionsViG,
//			'disabled' => false,
//			'readonly' => false,
//		));
		
		$fieldset->addField('ispersonalized', 'radios', array(
			'label' => Mage::helper('anc_album/data')->__('Personalisiert'),
			'name' => 'ispersonalized',
			'onclick' => "",
			'onchange' => "",
			'value' => '1',
			'values' => array(
				array('value' => '1', 'label' => 'Ja'),
				array('value' => '0', 'label' => 'Nein'),
			),
			'disabled' => false,
			'readonly' => false,
			'tabindex' => 1
		));
		
		
		
//		$varurlplaylists = $this->getUrl('site/adminhtml_playlist/list', array('id' => $data['entity_id'],));
		$arrayurl = array('textid' => $data['entity_id']);

		if ($data['ncright_id'] > 0) {
			$arrayurl['id'] = $data['ncright_id'];
		}

		$varurlrights = $this->getUrl('lib/adminhtml_ncrights/edit', $arrayurl
		);

		$fieldset->addType('ancbutton', 'Anc_Album_Lib_Varien_Data_Form_Element_ExtendedLabel');
		if($varParam['id']){
			$fieldset->addField('myrights', 'ancbutton', array(
				'label' => 'Rechte verwalten',
				'name' => 'myrights',
				'required' => false,
				'value' => $varurlrights,
				'bold' => true,
				'label_style' => '',
			));
		}
		
//			$fieldset->addField('mysaveandcontinue', 'ancbutton', array(
//				'label' => 'Speichern und weiter bearbeiten',
//				'name' => 'mysaveandcontinue',
//				'required' => false,
//				'value' => $this->getUrl('*/*/save', array( '_current'   => true,       'back'       => 'edit',)),
//				'bold' => true,
//				'label_style' => '',
//			));
		
		
		
//		$fieldset->addField('linkrights', 'link', array(
//			'label' => "zu:",
//			'style' => "test",
//			'href' => $this->getUrl('site/adminhtml_playlist/list', array('id' => $data['entity_id'],)),
//			'value' => 'Rechte verwalten',
//			'name' => 'linkrights',
//			'after_element_html' => ''
//		));

		/**
		 * Setzen der Hidden Id für Admin muss über den $data array erfolgen da sonst Magento für neue Elemente 0 setzt
		 */
		if ($varParam['kind'] === 'users' || $data['customer_id'] > 0) {
			
		} else {
			$data['admin_user_id'] = $admin = Mage::getSingleton('admin/session')->getUser()->getId();
			$fieldset->addField('admin_user_id', 'hidden', array('name' => 'admin_user_id'));
		}
		
		if ($varParam['albumid'] === 'users' || $data['customer_id'] > 0) {
			
		} else {
			$data['albumid'] = $varParam['albumid'];
			$fieldset->addField('albumid', 'hidden', array('name' => 'albumid'));
		}

//		D::s($data,'$data',5,1,1);
//		$data['path']= 'media/serviceplus/image/';
//		$fieldset->addField('file', 'text', array(
//			'label' => Mage::helper('anc_album/data')->__('Upload'),
//			'required' => false,
////			'value' => 'media/serviceplus/image/'.$data['file'],
//			'name' => 'file',
////			'path'=> 'media/serviceplus/text/',
////			'disabled' => false,
////			'readonly' => true,
//			'after_element_html' => $data['file'],
////			'tabindex' => 1
//		));



		if (!empty($data)) {
			$form->addValues($data);
		}
		/*
		 * Damit das Bild als preview angezeigt wird
		 */
//		$p = $form->getElement('file')->getValue();
//		$form->getElement('file')->setValue($data['path'] . $p);
		return parent::_prepareForm();
	}

}