<?php
/*******************************************************************************
* filename : orgbase.php
* last change : 2007 - 02 - 02
*
* http://www.avesan.it/
* Copyright 2006 Alberto Santoro
*
* PMbyAS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
******************************************************************************/
// --------------- connessione
require_once "./_fcom/fconn.php";
// --------------- sessione
require_once "./_fcom/fsess.php";
// --------------- dati di sessione
require_once "./_fcom/fperiodo.php";
// inclusione della testata HTML
require_once "./_fcom/doctype.php";
// ------------- inclusione barra navigazione
require_once "./_fcom/nav.php";
// --------------- verifica accesso
//$pgmtpo = 4;
//require_once "./_fcom/cnxpgm.php";
// -------------------- programma
$pgm = "orgbase.php";
// -------------------------------------------------------------- funzione
print "\n<div class=\"cpst\">";
print "\n<div class=\"dvtlab\">Organico</div>";
// --- Tipo Risorsa
$query = "SELECT * FROM tipo_risorsa WHERE TRsaCod = \"$SETRA\" ";
$oktra = mysqli_query($connessione,$query) or die("Query tra fallita");
$rgt = mysqli_fetch_assoc($oktra);
$nrec= mysqli_num_rows($oktra);
if ($nrec < 1) {$SETRA = "..."; $rsadex = "(non definita)";}
else $rsadex = $rgt["TRsaDex"];
print "\n<div class=\"dvpm130\">
<a href=\"traopt.php?pgm=$pgm\" title=\"cambia\">$SETRA $rsadex</a></div>";
// ----------------- periodo predefinito
$ani2=substr($SEani,2,2); $anf2=substr($SEanf,2,2);
$tsper="$SEggi.$SEmei.$ani2 - $SEggf.$SEmef.$anf2";
$tsgio="$SEggx.$SEmex.$SEanx";
print "\n<div class=\"dvpmsp40\"> </div>";
print "\n<div class=\"dvpm022\"><a href=\"shift_per.php?pgm=$pgm&sh=m14\" title=\"- 14 gg\"><<</a></div>";
print "\n<div class=\"dvpm012\"><a href=\"shift_per.php?pgm=$pgm&sh=m07\" title=\"- 7 gg\"><</a></div>";
print "\n<div class=\"dvpm120\"><a href=\"peropt.php?pgm=$pgm\" title=\"cambia\">$tsper</a></div>";
print "\n<div class=\"dvpm012\"><a href=\"shift_per.php?pgm=$pgm&sh=p07\" title=\"+ 7 gg\">></a></div>";
print "\n<div class=\"dvpm022\"><a href=\"shift_per.php?pgm=$pgm&sh=p14\" title=\"+ 14 gg\">>></a></div>";
print "\n<div class=\"dvpmsp\"> </div>";
print "</div><br />";
// ------------- estrazione validità in tbella temporanea
$query = "DROP TABLE IF EXISTS organico";
$rs_drop = mysqli_query($connessione,$query) or die("Query drop organico fallita");
$query = "CREATE TABLE organico ENGINE = MYISAM
SELECT RsuCod AS OrgCod, RsuDex AS OrgDex FROM pge_ru ORDER BY RsuCod";
$oktmp = mysqli_query($connessione,$query) or die("Query tmp rsu fallita");
$query = " ALTER TABLE organico
ADD PRIMARY KEY (OrgCod),
ADD COLUMN OrgDay DATE NOT NULL default '2060-01-01' AFTER OrgDex,
ADD COLUMN OrgCcs CHAR(10)BINARY NOT NULL default ' ' AFTER OrgDay";
$ralt = mysqli_query($connessione,$query) or die("Query alter organico fallita");
//$query = " ALTER TABLE organico
// ADD PRIMARY key (OrgCod) ";
//$ralt = mysqli_query($connessione,$query) or die("Query alter organico fallita");
//$query = " ALTER TABLE organico
// ADD OrgDay DATE NOT NULL DEFAULT '2060-01-01' AFTER OrgDex";
//$ralt2 = mysqli_query($connessione,$query) or die("Query alter 2 organico fallita");
//$query = " ALTER TABLE organico
// ADD OrgCcs CHAR(10)BINARY NOT NULL DEFAULT ' ' AFTER OrgDay";
//$ralt3 = mysqli_query($connessione,$query) or die("Query alter 2 organico fallita");
$query = "SELECT * FROM pge_ru ORDER BY RsuCod";
$okru = mysqli_query($connessione,$query) or die("Query rsu fallita");
while ($rgu = mysqli_fetch_assoc($okru)) {
$query = "SELECT * FROM pge_ru_val
WHERE RsuvCod = \"{$rgu["RsuCod"]}\" and RsuDay <= \"$SEDTI\"
ORDER BY RsuvCod, RsuDay DESC ";
$stok = mysqli_query($connessione,$query) or die("Query vrsa fallita");
$nday = mysqli_num_rows($stok);
$rgs = mysqli_fetch_assoc($stok);
// print "{$rgs["RsuDay"]}; {$rgs["RsuCCS"]}; {$rgu["RsuCod"]}; --";
if ($nday > 0) {
$query = "UPDATE organico
SET OrgDay = \"{$rgs["RsuDay"]}\", OrgCcs = \"{$rgs["RsuCCS"]}\"
WHERE OrgCod = \"{$rgu["RsuCod"]}\"";
$inok = mysqli_query($connessione,$query) or die("Query ins lav fallita"); }}
// ---------------------------------------------------------------------------
$query = "SELECT * FROM pge_rsa WHERE RsaPk = \"$SETRA\" ORDER BY RsaCod";
$stok = mysqli_query($connessione,$query) or die("Query gen fallita");
// -------------------------- Testata
print "\n<div class=\"cpnn\">";
print "\n<table ><thead><tr>";
//print "\n<th width=\"18\"> </th>";
print "\n<th class=\"t8s\" width=\"95\">codice</th>";
print "\n<th class=\"t8s\" width=\"220\">descrizione</th>";
print "\n<th class=\"t8c\" width=\"20\">cla</th>";
print "\n<th class=\"t8c\" width=\"20\">tpo</th>";
print "\n<th class=\"t8s\" width=\"95\">voce piano</th>";
print "\n<th class=\"t8s\" width=\"95\">centro resp.</th>";
print "\n<th class=\"t8c\" width=\"40\"> </th>";
print "\n<th class=\"t8c\" width=\"60\">risorsa</th>";
print "\n<th class=\"t8s\" width=\"200\">descrizione</th>";
print "\n<th class=\"t8c\" width=\"80\">dal</th>";
// --- corpo scrollabile
print "\n<th class=\"t8c\" width=\"20\"> </th>";
print "\n</tr></thead>";
print "\n<tbody><tr><td colspan=\"11\"><div class=\"win380\"><table class=\"tbover\">";
// --------------------------- righe dettaglio
$xt = 0;
while ($rg = mysqli_fetch_assoc($stok)) {
// print "\n<tr><td width=\"18\" class=\"pup\" >
// <a href=\"pgdvar.php?com=V&rsapk={$rg["RsaPk"]}&rsacod={$rg["RsaCod"]}\"> ¤ </td>";
print "\n<td width=\"95\"class=\"c8sg\">{$rg["RsaCod"]}</td>";
print "\n<td width=\"220\" class=\"c8s\">{$rg["RsaDex"]}</td>";
print "\n<td width=\"20\" class=\"c8c\">{$rg["RsaCla"]}</td>";
print "\n<td width=\"20\" class=\"c8c\">{$rg["RsaTpo"]}</td>";
print "\n<td width=\"95\" class=\"c8s\">{$rg["RsaPge"]}</td>";
print "\n<td width=\"95\" class=\"c8s\">{$rg["RsaUO"]}</td>";
print "\n<td width=\"300\" class=\"c8s\" colspan=\"3\"> </td>";
print "</tr>";
if ($rg["RsaPk"] == "RU") {
$query = "SELECT * FROM organico
WHERE OrgCcs = \"{$rg["RsaCod"]}\" AND OrgDay <= \"$SEDTI\" ORDER BY OrgCod";
$vlok = mysqli_query($connessione,$query) or die("Query val fallita");
$xx = 0;
while ($rv = mysqli_fetch_assoc($vlok)) {
$xx = $xx +1;
if ($rg["RsaCod"] <> "***") { $xt = $xt + 1;}
// print "\n<tr><td width=\"18\" class=\"c8nn\"> </td>";
print "\n<tr><td colspan =\"6\" class=\"tdsp\"> </td>";
print "\n<td width =\"40\" class=\"c8c\">$xx</td>";
print "\n<td width =\"40\" class=\"c8c\">{$rv["OrgCod"]}</td>";
print "\n<td width =\"200\" class=\"c8s\">{$rv["OrgDex"]}</td>";
print "\n<td width =\"80\" class=\"c8c\">{$rv["OrgDay"]}</td></tr>";
} }
}
print "\n</tr>";
if ($xt > 0) {
// print "\n<tr><td width=\"18\" class=\"tdsp\"> </td>";
print "\n<tr><td colspan =\"6\" class=\"c8d\">totale organico </td>";
print "\n<td class=\"c8cg\">$xt</td>";
print "\n<td colspan=\"2\" class=\"c8s\"> </td></tr>";}
print "\n</table>";
// --------------------------------------------- Fine tabella
print "\n</div></td></tr></tbody>"; // --- chiusura corpo tabella
// --------------------- piede tabella
print "\n<tfoot><tr>";
print "\n<td class=\"pd8s\"colspan=\"11\"> </td>";
// ---------------------------------
print "\n</tr></tfoot></table</div>";
?>
</div></body></html>