Your IP : 216.73.216.170


Current Path : /var/www/iplanru/data/www/i-plan.ru/components/com_pay/models/
Upload File :
Current File : /var/www/iplanru/data/www/i-plan.ru/components/com_pay/models/payonline.php

<?php

// No direct access
defined( '_JEXEC' ) or die;

/**
 * Model for edit/create current element
 * @author kirdinyuri
 */
class PayModelPayonline extends JModelAdmin
{
	/**
	 * @var JInput|null
	 */
	private $input;

	/**
	 * classs constructor
	 * @param array $config
	 */
	public function __construct( $config = array() )
	{
		parent::__construct( $config );
		$this->input = JFactory::getApplication()->input;
	}

	/**
	 * Method of loading the current form
	 * @param Array $data
	 * @param Boolean $loadData
	 * @return Object form data
	 */
	public function getForm( $data = array(), $loadData = true )
	{
		$form = $this->loadForm( '', 'payonline', array( 'control' => 'jform', 'load_data' => $loadData ) );
		if ( empty( $form ) ) {
			return false;
		}
		
		$componentParams = &JComponentHelper::getParams('com_pay');
		
		
		$jinput = JFactory::getApplication()->input;
		$method=$jinput->getString( 'method', '' );
		$matid=$jinput->getInt( 'item_id', 0 );
		
		if (!$form->getValue( 'method')) $form->setValue( 'method', null, $method );
		$form->setValue( 'cs', null, '' );
		$form->setValue( 'date', null, date("Y-m-d H:i:s") );
		if (!$form->getValue( 'matid'))$form->setValue( 'matid', null, $matid );
		
		if (!empty($matid))
		{
			$db =&JFactory::getDBO();
			$db->setQuery('SELECT elements as val FROM #__zoo_item where id='.$matid, 0, $count=0);
			$rows = $db->loadObjectList();
			if (count($rows)<>0)
			foreach ($rows as $row) {$mat=$row->val;};					
			$array_json=json_decode($mat, true);
			if ($array_json["43191a2a-0fb3-4578-b7e0-dbf5e584873d"]["option"]['0']=="est")
				$cost_text=$array_json['dbf6c773-0a69-432c-a462-b56e620e2e5e']['0']['value'];
			else
				$cost_text=$array_json['aed9068f-8fd9-4c38-89d1-83187a602ac5']['0']['value'];
			$cost_text = preg_replace('~[^0-9.,]+~', '', $cost_text);
			$form->setValue( 'cost_text', null, $cost_text );
		}
		
		$form->setValue( 'oferta', null, $componentParams->get('oferta', '') );
		
		return $form;
	}
	

	/**
	 * Method of loading table for current item
	 * @param Sting $type (name table)
	 * @param String $prefix (prefix table)
	 * @param Array $config
	 * @return Object (The object reference table)
	 */
	public function getTable( $type = 'payment', $prefix = 'Table', $config = array() )
	{
		return JTable::getInstance( $type, $prefix, $config );
	}

	/**
	 * Method of loading data to form
	 * @return Object
	 */
	protected function loadFormData()
	{
		$data = JFactory::getApplication()->getUserState( 'com_pay.edit.payonline.data', array() );
		if ( empty( $data ) ) {
			$data = $this->getItem();
		}
		return $data;
	}


		public function pk( $data )
	{

		
		JFactory::getApplication()->enqueueMessage( print_r($data, true) );
		
		return parent::pk( $data );
	}


	/**
	 * save data
	 * @param array $data
	 * @return bool
	 */
	public function save( $data )
	{
		$db =&JFactory::getDBO();
		
		$componentParams = &JComponentHelper::getParams('com_pay');
		$mmail = $componentParams->get('mmail', '');
		$mmail=explode(",", $mmail);
		
		if (!empty($data[matid]))
		{	
			$list = $db->setQuery( 'SELECT name FROM #__zoo_item where id='.$data[matid] )->loadAssoc();
			$name_mat=$list[name];
			unset($list);
		}
		
		$list = $db->setQuery( 'SELECT (max(id)+1) as id FROM #__payment' )->loadAssoc();
		$payid=$list[id];
		unset($list);
		
		if (!empty($data[cost_text_discount]))
			$cost_text=$data[cost_text_discount];
		else
			$cost_text=$data[cost_text];
		
		//==============================================================
		$msg[]='<html><head></head><body>';
		$msg[]='<div id="page" style="width:690px; margin: auto; font-family: \"Arial\", \"Tahoma\", \"Times New Roman\", serif; font-size: 12px;">';
		$msg[]='<div id="header" style="width:100%"><img src="http://i-plan.ru/components/com_pay/views/payment/tmpl/images/header1.jpg" 
				alt="Intesco Research Group. 
				Разработка бизнес-планов для ведущих банков РФ. 
				г. Москва, ул. Бауманская, 33/2 +7 (495) 645-97-22 info@i-plan.ru"/></div>';
		
		$msg[]='<div id="caption" style="font-size: 22px; margin: 28px 5px; text-align: center;">';
		$msg[]='Форма заказа c оплатой он-лайн';
		$msg[]='</div>';
		
		$msg[]='<table width=65% style="margin: auto; font-size: 12px;">';
		
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">ФИО:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \">{$data[fio]}</td></tr>";
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">Email:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \"><a id=\"mail\" style=\"text-decoration: none; color: black;\" href=\"mailto:{$data[mail]}\">{$data[mail]}</a></td></tr>";
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">Телефон:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \">{$data[tel]}</td></tr>";
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">ID платежа в БД:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \">{$payid}</td></tr>";
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">ID Материала:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \">{$data[matid]}</td></tr>";
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">Наименование работы:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \">{$name_mat}</td></tr>";
		$msg[]="<tr><td id=\"colcost1\" style=\"text-align: center; background: #c95c24; padding: 12px; color: white;\">Стоимость работы:</td>
			<td id=\"colcost2\" style=\"background: #f4f4f4; padding: 12px;\"><span style=\"font-size: 20px;\">{$cost_text}</span> руб.</td></tr>";
					
		$msg[]='</table>';
		$msg[]='<div id="footer" style="margin-top: 50px; text-align: center; font-size: 9px;">Все права защищены и охраняются законом. © 2007 - 2013 Intesco Research Group.</div>';
		$msg[]='</div>';
		$msg[]='</body></html>';
			
		$msg=implode("\r\n",$msg);
		$subject="Оплата он-лайн:{$payid} Работа <{$data[matid]}> (менеджеру)";
		
		$mailer =& JFactory::getMailer();						
		$conf = new JConfig();
		$sender = array( 
			$conf->mailfrom,
			$conf->fromname);
		$mailer->setSender($sender);		
		$mailer->addRecipient($mmail);
		$mailer->setSubject($subject);
		$mailer->isHTML(true);
		$mailer->Encoding = 'base64';
		$mailer->setBody($msg);
		$send =& $mailer->Send();
		
		unset($msg);
		
		//==============================================================
		$msg[]='<html><head></head><body>';
		$msg[]='<div id="page" style="width:690px; margin: auto; font-family: \"Arial\", \"Tahoma\", \"Times New Roman\", serif; font-size: 12px;">';
		$msg[]='<div id="header" style="width:100%"><img src="http://i-plan.ru/components/com_pay/views/payment/tmpl/images/header1.jpg" 
				alt="Intesco Research Group. 
				Разработка бизнес-планов для ведущих банков РФ. 
				г. Москва, ул. Бауманская, 33/2 +7 (495) 645-97-22 info@i-plan.ru"/></div>';
		
		$msg[]='<div id="caption" style="font-size: 22px; margin: 28px 5px; text-align: center;">';
		$msg[]='Форма заказа c оплатой он-лайн';
		$msg[]='</div>';
		
		$msg[]='<table width=65% style="margin: auto; font-size: 12px;">';
		
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">ФИО:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \">{$data[fio]}</td></tr>";
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">Email:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \"><a id=\"mail\" style=\"text-decoration: none; color: black;\" href=\"mailto:{$data[mail]}\">{$data[mail]}</a></td></tr>";
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">Телефон:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \">{$data[tel]}</td></tr>";
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">ID Материала:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \">{$data[matid]}</td></tr>";
		$msg[]="<tr><td id=\"col1\" style=\"text-align: center; background: #e7f2c8; padding: 10px; width: 100px;\">Наименование работы:</td>
			<td id=\"col2\" style=\" background: #f4f4f4; padding: 12px; \">{$name_mat}</td></tr>";
		$msg[]="<tr><td id=\"colcost1\" style=\"text-align: center; background: #c95c24; padding: 12px; color: white;\">Стоимость работы:</td>
			<td id=\"colcost2\" style=\"background: #f4f4f4; padding: 12px;\"><span style=\"font-size: 20px;\">{$cost_text}</span> руб.</td></tr>";
		
					
		$msg[]='</table>';
		$msg[]='<div id="footer" style="margin-top: 50px; text-align: center; font-size: 9px;">Все права защищены и охраняются законом. © 2007 - 2013 Intesco Research Group.</div>';
		$msg[]='</div>';
		$msg[]='</body></html>';
			
		$msg=implode("\r\n",$msg);
		$subject="Оплата он-лайн";
		
		$mailer =& JFactory::getMailer();						
		$conf = new JConfig();
		$sender = array( 
			$conf->mailfrom,
			$conf->fromname);
		$mailer->setSender($sender);		
		$mailer->addRecipient($data[mail]);
		$mailer->setSubject($subject);
		$mailer->isHTML(true);
		$mailer->Encoding = 'base64';
		$mailer->setBody($msg);
		$send =& $mailer->Send();
		
		unset($msg);
		
		//JFactory::getApplication()->enqueueMessage( print_r($data, true) );
		
		return parent::save( $data );
	}
	


}