<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
	$mod_template="places_list.tpl";
	
	if ($_SERVER['REQUEST_METHOD']=='POST')
	{
		if ($_POST['rate']) foreach ($_POST['rate'] as $id=>$value)
		{
			Db::i()->query("UPDATE ?_ad_rotator_values SET rate=? WHERE id=?", intval($value), $id);
		}
		refresh();
	}
	
	$result=Db::i()->select("SELECT p.place_id, name, `describe`, p.active as place_active, value_name, value, id, rate, v.active FROM ?_ad_rotator_places p LEFT JOIN ?_ad_rotator_values v ON p.place_id=v.place_id ORDER BY name, p.active DESC");
	$places=array();
	if ($result) foreach($result as $var)
	{
		if (!$places[$var['place_id']]) $places[$var['place_id']]=array('name'=>$var['name'],
										'describe'=>$var['describe'],
										'active'=>$var['place_active']);
		if ($var['id'])	$places[$var['place_id']]['vars'][$var['id']]=array(
													'value_name'=>$var['value_name'],
													'value'=>$var['value'],
													'rate'=>$var['rate'],
													'active'=>$var['active']);
	}
	Tpl::i()->assign('places', $places);