<?php require_once('Connections/receitas.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login/login_admin.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
// technocurve arc 3 php bv block1/3 start
$color1 = "#FFCCCC";
$color2 = "#FFFF99";
$color = $color1;
// technocurve arc 3 php bv block1/3 end

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Rsreceitas = 50;
$pageNum_Rsreceitas = 0;
if (isset($_GET['pageNum_Rsreceitas'])) {
  $pageNum_Rsreceitas = $_GET['pageNum_Rsreceitas'];
}
$startRow_Rsreceitas = $pageNum_Rsreceitas * $maxRows_Rsreceitas;

mysql_select_db($database_receitas, $receitas);
$query_Rsreceitas = "SELECT * FROM receitas ORDER BY titulo ASC";
$query_limit_Rsreceitas = sprintf("%s LIMIT %d, %d", $query_Rsreceitas, $startRow_Rsreceitas, $maxRows_Rsreceitas);
$Rsreceitas = mysql_query($query_limit_Rsreceitas, $receitas) or die(mysql_error());
$row_Rsreceitas = mysql_fetch_assoc($Rsreceitas);

if (isset($_GET['totalRows_Rsreceitas'])) {
  $totalRows_Rsreceitas = $_GET['totalRows_Rsreceitas'];
} else {
  $all_Rsreceitas = mysql_query($query_Rsreceitas);
  $totalRows_Rsreceitas = mysql_num_rows($all_Rsreceitas);
}
$totalPages_Rsreceitas = ceil($totalRows_Rsreceitas/$maxRows_Rsreceitas)-1;

$queryString_Rsreceitas = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Rsreceitas") == false && 
        stristr($param, "totalRows_Rsreceitas") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Rsreceitas = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Rsreceitas = sprintf("&totalRows_Rsreceitas=%d%s", $totalRows_Rsreceitas, $queryString_Rsreceitas);
?>
<!doctype html>
 <html class="">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lista de Receitas</title>
<link href="css/boilerplate.css" rel="stylesheet" type="text/css">
<link href="css/estilosreceitas.css" rel="stylesheet" type="text/css">
<!--<!>link href="css/menunavbar.css" rel="stylesheet" type="text/css">





<!-- 
Para saber mais sobre os comentários condicionais sobre as tags html na parte superior do arquivo:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

Se você estiver usando a compilação personalizada do modernizr (http://www.modernizr.com/), faça o seguinte:
* insira o link para o seu js aqui
* remova o link abaixo para o html5shiv
* adicione a classe "no-js" às tags html na parte superior
* você também pode remover o link para respond.min.js se tiver incluído o MQ Polyfill na sua compilação do modernizr 
-->
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="../js/respond.min.js"></script>
</head>
<body>
	
	    <p>&nbsp;</p>
<table width="800" border="0" align="center" cellspacing="20">
          <tr >
            <td align="center"><span class="stilo2">LISTA RECEITAS</span></td>
          </tr>
          <tr>
            <td align="center" class="stilo2">&nbsp;</td>
          </tr>
          <tr>
            <td align="center" class="stilo2"><span class="stilo1">TOTAL DE RECEITAS =</span> <?php echo $totalRows_Rsreceitas ?></td>
          </tr>
          <tr>
            <td align="center" class="stilo1">&nbsp;</td>
          </tr>
          <tr>
            <td align="center" bgcolor="#CCCCFF" class="stilo2"><?php
for ($i=0; $i <= $totalPages_Rsreceitas; $i++) {
  $TFM_PagesEndCount = $i + 1;
  if($i != $pageNum_Rsreceitas) {
    printf('<a href="'."%s?pageNum_Rsreceitas=%d%s", $currentPage, $i, $queryString_Rsreceitas.'">'.$TFM_PagesEndCount."</a>");
  }else{
    echo("<b>$TFM_PagesEndCount</b>");
  }
  if($i != $totalPages_Rsreceitas) echo(" | ");
}
 ?></td>
          </tr>
          <tr>
            <td align="center" class="stilo1">&nbsp;</td>
          </tr>
</table>

	    <table width="800" border="1" align="center" cellpadding="7" cellspacing="3">
        <?php do { ?>
        <tr <?php 
// technocurve arc 3 php bv block2/3 start
echo " style=\"background-color:$color\"";
// technocurve arc 3 php bv block2/3 end
?>>
          <td width="5">&nbsp;</td>
          <td width="330" class="stilo1"><a href="receita.php?id=<?php echo $row_Rsreceitas['id']; ?>=<?php echo $row_Rsreceitas['id']; ?>"><?php echo $row_Rsreceitas['titulo']; ?> || <?php echo $row_Rsreceitas['autor']; ?></a></td>
          
          <td width="80" class="stilo2"><?php echo $row_Rsreceitas['categoria']; ?></td>
          <td width="50" class="stilo1"><a href="editar.php?id=<?php echo $row_Rsreceitas['id']; ?>">EDITAR</a></td>
          <td width="5"></td>
          <td width="70"><a href="excluir.php?id=<?php echo $row_Rsreceitas['id']; ?>"><img src="imagens/btExcluir2.gif" width="75" height="25" border="0" /></a></td>
        </tr>
        <?php 
// technocurve arc 3 php bv block3/3 start
if ($color == $color1) {
	$color = $color2;
} else {
	$color = $color1;
}
// technocurve arc 3 php bv block3/3 end
?>
<?php } while ($row_Rsreceitas = mysql_fetch_assoc($Rsreceitas)); ?>
      </table>
<table width="800" border="0" align="center" cellspacing="20">
          <tr >
            <td width="369" align="right">&nbsp;</td>
            <td width="367" align="center">&nbsp;</td>
          </tr>
          <tr >
            <td colspan="2" align="center" bgcolor="#CCCCFF" class="stilo2"><?php
for ($i=0; $i <= $totalPages_Rsreceitas; $i++) {
  $TFM_PagesEndCount = $i + 1;
  if($i != $pageNum_Rsreceitas) {
    printf('<a href="'."%s?pageNum_Rsreceitas=%d%s", $currentPage, $i, $queryString_Rsreceitas.'">'.$TFM_PagesEndCount."</a>");
  }else{
    echo("<b>$TFM_PagesEndCount</b>");
  }
  if($i != $totalPages_Rsreceitas) echo(" | ");
}
 ?></td>
  </tr>
          <tr >
            <td colspan="2" align="center"><span class="stilo1">TOTAL DE RECEITAS =</span>&nbsp;<span class="stilo2"><?php echo $totalRows_Rsreceitas ?></span></td>
          </tr>
          <tr >
            <td align="center"><span class="stilo2"><a href="inicio.php">VOLTAR</a></span></td>
            <td align="center"><span class="stilo2"><a href="inserir.php">INSERIR</a></span></td>
          </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Rsreceitas);
?>
