CustomerController.php 7.11 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_CustomerController extends Mage_Core_Controller_Front_Action {

	protected function _initAction() {
		$this->loadLayout();
		return $this;
	}

	/**
	 * Block/Template Funktion
	 * 
	 * fnc ist in "mein Benutzerkonto" laut @see app/design/frontend/layout/anc_text.xml als link aufrufbar,
	 * * durch selbige anc_text.xml bekommt die fnc das template @see app/design/frontend/template/anctext/customer_galleriesmanager.phtml beigesteuert
	 */
	public function galleriesmanagerAction() {
		$this->loadLayout();
		$this->getLayout()->getBlock('root')->setTemplate('page/2columns-right.phtml');
		$this->renderLayout();
	}

	/**
	 * param - $this->getRequest()->getParams()['id'] -- id des zu bearbeiteten nctext
	 * 
	 * Block/Template Funktion
	 * 
	 */
	public function shownctextformAction() {
		if (Mage::getSingleton('customer/session')->isLoggedIn()) {
			$params = $this->getRequest()->getParams();
			if (is_array($params) && array_key_exists('id', $params)) {
				
				if($params['id']==0){
					/**
					 * Wenn ein neuer Text erstellt wird
					 */
					$params['id'] = Mage::helper('anc_text/ncmodel')->createNCNew();
					$this->getRequest()->setParams('id',$params['id']);
					Mage::app()->getRequest()->setParam('id',$params['id']);

				}
				$nctext = Mage::helper('anc_text/ncmodel')->getNcText($params['id']);

				if (is_object($nctext)) {

					if (array_key_exists('name', $params)) {
						$nctext->setName($params['name']);
					}
					if (array_key_exists('comment', $params)) {
						$nctext->setComment($params['comment']);
					}
					$nctext = Mage::helper('anc_text/ncmodel')->saveNcText($nctext);
				}
			}
			$this->loadLayout();
			$this->getLayout()->getBlock('root')->setTemplate('page/empty.phtml');
			$this->getLayout()->getBlock('content')->append(
			$this->getLayout()->createBlock('anc_text/galleriesmanager')->setTemplate('anc/image/customer_showNcTextForm.phtml')
			);	
			
			$this->renderLayout();
		} else {
			echo('nicht eingeloggt');
		}
	}

	public function gallerysimpleAction() {
		$this->loadLayout();
		$this->getLayout()->getBlock('root')->setTemplate('page/empty.phtml');
		$this->renderLayout();
	}

	/**
	 * @param _POST[id] => $this->getRequest()->getParams()[id] -- anc_text/nctext id
	 * 
	 */
	public function deleteNcTextAction() {
		$params = $this->getRequest()->getParams();
		$json_rueckgabe = array();
		if (array_key_exists('id', $params) && $params['id']) {
			$param_id = $params['id'];

			$nctext = Mage::helper('anc_text/ncmodel')->getNcText($param_id);

			if (Mage::helper('anc_text/ncmodel')->deleteNcText($nctext)) {
				$json_rueckgabe['status'] = 'OK';
				$json_rueckgabe['message'] = 'Der Text(' . $nctext->getId() . ' wurde gelöscht)!';
			} else {
				$json_rueckgabe['status'] = 'ERROR';
				$json_rueckgabe['message'] = 'Es ist beim Löschen ein Fehler aufgetreten!';
			}
		} else {
			$json_rueckgabe['status'] = 'ERROR';
			$json_rueckgabe['message'] = 'Keine ID angegeben!';
		}

		echo json_encode($json_rueckgabe);
	}

	
	
	
	
	/**
	 * @param optional _POST[id] => $this->getRequest()->getParams()[id] -- anc_text/nctext id
	 * 
	 * fnc wird übers formular von galleriesmanagerAction() bzw customer_galleriesmanager.phtml 
	 * bei einem datei upload aufgerufen und verarbeitet die post werte 
	 * * kopiert datei in entsprechendes kunden verzeichniss
	 * * speichert dateiname im model / in tabelle
	 */
	public function savecustomertextAction() {
		//ncinput_id: ncinput_id, option_id: option_id,ncalbum_id: ncalbum_id,nccustomerid:nccustomerid,ncadmin_id:ncadmin_id,used_byitem_id:used_byitem_id,ordered:ordered,varcontent:varcontent
		$params = $this->getRequest()->getParams();
		if (array_key_exists('id', $params)) {
			$param_id = $params['id'];
		} else {
			$param_id = false;
		}

		if (array_key_exists('ncalbum_id', $params)) {
			$param_ncalbum_id = $params['ncalbum_id'];
		} else {
			$param_ncalbum_id = false;
		}

		$json_rueckgabe = array();
		if (Mage::getSingleton('customer/session')->isLoggedIn()) {
			$customerData = Mage::getSingleton('customer/session')->getCustomer();
//			echo $customerData->getId();
		} else {
//			$this->_getSession()->addError('Bitte melden sie sich an um Ihr Produkt zu Personalisieren');
		}

		$texts = Mage::helper('anc_text/ncmodel')->getNcTextsForCustomer();

		$var_albums = Mage::helper('anc_album/ncmodel')->getNcAlbumsForCustomer()->getData();
		if (!$var_albums[0]) {
			$albumid = Mage::helper('anc_album/ncmodel')->createNcAlbumForCustomer();
			$var_albums = Mage::helper('anc_album/ncmodel')->getNcAlbumsForCustomer()->getData();
		} else {
			$albumid = $var_albums[0]['entity_id'];
		}
		$params['album_id'] = $albumid;
		$textid = Mage::helper('anc_text/ncmodel')->prepareSaveNcText($params);

		if ($textid) {

			$json_rueckgabe['model'] = 'anc_text/nctext';
			$json_rueckgabe['id'] = $textid; //$nctext->getId();			
			$json_rueckgabe['status'] = 'OK';
			$json_rueckgabe['message'] = 'upload erfolgreich !! (' . $textid . ')';
		} else {
			$json_rueckgabe['status'] = 'ERROR';
			$json_rueckgabe['message'] = 'Text1 konnte nicht auf dem Server gespeichert werden';
		}
		echo json_encode($json_rueckgabe);
	}

	public function getcustomertextdataAction() {
		$params = $this->getRequest()->getParams();
		if ($params['entity_id']) {
			$texts = Mage::helper('anc_text/ncmodel')->getNcText($params['entity_id']);
			$json_rueckgabe = array();
			$json_rueckgabe['model'] = 'anc_text/nctext';
			$json_rueckgabe['entity_id'] = $texts['entity_id'];
			$json_rueckgabe['customer_id'] = $texts['customer_id'];
			$json_rueckgabe['admin_user_id'] = $texts['admin_user_id'];
			$json_rueckgabe['name'] = $texts['name'];
			$json_rueckgabe['name'] = $texts['name'];
			$json_rueckgabe['content'] = $texts['content'];
			$json_rueckgabe['ncalbum_id'] = $texts['ncalbum_id'];
			$json_rueckgabe['original_id'] = $texts['original_id'];
			$json_rueckgabe['ncright_id'] = $texts['ncright_id'];
			$json_rueckgabe['ordered'] = $texts['ordered'];
			$json_rueckgabe['used_byitem_id'] = $texts['used_byitem_id'];
			$json_rueckgabe['visibleingallery'] = $texts['visibleingallery'];
			$json_rueckgabe['status'] = 'OK';
			$json_rueckgabe['message'] = 'erfolgreich !! (' . $texts['entity_id'] . ')';
		} else {
			$json_rueckgabe['status'] = 'ERROR';
			$json_rueckgabe['message'] = 'Text2 konnte nicht auf dem Server gespeichert werden';
		}
		echo json_encode($json_rueckgabe);
	}

}