<?php

/**
 * KataoMemberDeposit form.
 *
 * @package form
 * @subpackage katao_member_deposit
 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class KataoMemberDepositForm extends BaseKataoMemberDepositForm {
	public function configure() {
		unset($this->validatorSchema['valued_at'], $this->validatorSchema['check_deposit'], $this->validatorSchema['created_at'], $this->validatorSchema['updated_at']);
		unset($this->widgetSchema['valued_at'], $this->widgetSchema['check_deposit'], $this->widgetSchema['created_at'], $this->widgetSchema['updated_at']);

		$sf_user = sfContext::getInstance()->getUser();
		if ($sf_user->isJustDelegate()) {
			$this->widgetSchema['katao_member_id'] = new sfWidgetFormSelect(array('choices' => KataoMemberPeer::getAll(false, false, $sf_user->getInstance()->getKataoMember()->getKataoNodeId())));
		} else {
			$this->widgetSchema['katao_member_id'] = new sfWidgetFormSelect(array('choices' => KataoMemberPeer::getAllGroupedByNode()));
		}

		$this->widgetSchema['amount'] = new sfWidgetFormInput(array(), array('style' => 'width: 50px; text-align: right'));
		$this->widgetSchema['comment'] = new sfWidgetFormTextarea(array(), array('style' => 'width: 250px; height: 100px'));
		$this->widgetSchema['check_number'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
		$this->widgetSchema['check_bank'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));

		$this->widgetSchema['currency'] = new sfWidgetFormSelect(array('choices' => KataoMemberDepositPeer::getAllCurrencies()));
		$this->widgetSchema['payment_mode'] = new sfWidgetFormSelect(array('choices' => KataoMemberDepositPeer::getAllPaymentModes()), array('onchange' => 'togglePaymentModeDetails();'));
		$this->widgetSchema['status'] = new sfWidgetFormSelect(array('choices' => KataoMemberDepositPeer::getAllStatuses()), array('onchange' => 'toggleStatusDetails();'));

		$this->widgetSchema['valid_until'] = new wpWidgetFormRichDate();
		$this->validatorSchema['valid_until'] = new sfValidatorDateTime(array('required' => false, 'date_format' => '@(?P<day>\d{2}).(?P<month>\d{2}).(?P<year>\d{4})@'));

		$this->widgetSchema->setLabels(array(
				'katao_member_id' => 'Adhérent',
				'amount' => 'Montant',
				'currency' => 'Monnaie',
				'comment' => 'Commentaires',
				'payment_mode' => 'Mode de règlement',
				'check_number' => 'N° de chèque',
				'check_bank' => 'Banque émettrice',
				'status' => 'Etat',
				'valid_until' => 'Date butoir',
				));
	}

	public function doSave($con = null) {
		if ($this->getObject()->isNew()) {
			$this->getObject()->setValuedAt(time());
		}
		return parent::doSave($con);
	}
}