<?php
namespace admin\factory;

class MenuManager
{
	public function delete( $id )
	{
		global $sys , $lang , $db;

		$flag	= true;

		$query = $db -> prepare( 'SELECT count(id) FROM pcms_page WHERE id_menu=:id_menu' );
		$query -> bindValue( ':id_menu' , $id , \PDO::PARAM_INT );
		$query -> execute();
		if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
		{
			if ( $row[0] > 0 )
			$flag = false;
		}
		$query -> closeCursor();

		if ( $flag )
		{
			$query 	= $db -> prepare( 'DELETE FROM pcms_menu WHERE id=:id' );
			$query -> bindValue( ':id' , $id , \PDO::PARAM_INT );
			$query -> execute();
			$query -> closeCursor();
			$sys -> setAlert( $lang -> getTrans( 'T_USUNIETO_MENU' ) );
		}
		else
			$sys -> setAlert( $lang -> getTrans( 'T_NIE_MOZNA_USUNAC_MENU_ZAWIERA_STRONY' ) );
	}
}
?>