Merge pull request 'Consultar estado de reserva de un aula' (#15) from consultar-reserva into main

Reviewed-on: #15
pull/18/head
Natalia Serrano 2024-04-10 12:57:32 +02:00
commit 22813edae0
4 changed files with 71 additions and 5 deletions

View File

@ -10,4 +10,8 @@ CREATE TABLE `calendarios` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
ALTER TABLE `aulas`
ADD `idcalendario` int(3) DEFAULT NULL;
ADD `idcalendario` int(3) DEFAULT NULL,
ADD `remotepc_reserved` int(1) DEFAULT 0;
ALTER TABLE `ordenadores`
DROP `inremotepc`;

View File

@ -153,6 +153,7 @@ CREATE TABLE `aulas` (
`inremotepc` tinyint NOT NULL DEFAULT 0,
`oglivedir` varchar(50) NOT NULL DEFAULT 'ogLive',
`idcalendario` int(3) DEFAULT NULL,
`remotepc_reserved` int(1) DEFAULT 0,
PRIMARY KEY (`idaula`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
@ -549,7 +550,6 @@ CREATE TABLE `ordenadores` (
`paginavalidacion` varchar(100),
`agentkey` varchar(32),
`oglivedir` varchar(50) NOT NULL DEFAULT 'ogLive',
`inremotepc` tinyint NOT NULL DEFAULT 0,
`maintenance` tinyint NOT NULL DEFAULT 0,
PRIMARY KEY (`idordenador`),
KEY `idaulaip` (`idaula` ASC, `ip` ASC)

View File

@ -62,6 +62,7 @@ $gidrepositorio=0;
$gidperfilhard=0;
$oglive="";
$cntDiff=0;
$remotepc_reserved=0;
if (isset($_GET["opcion"])) $opcion=$_GET["opcion"]; // Recoge parametros
if (isset($_GET["idaula"])) $idaula=$_GET["idaula"];
@ -246,6 +247,13 @@ function abrir_ventana(URL){
}
?>
</tr>
<!------------------------------------remotepc_reserved-------------------------------------------------------------------------------------------------------------------------------->
<tr>
<th align="center">&nbsp;Aula&nbsp;reservada&nbsp;</th>
<td colspan="3">
<?php echo $remotepc_reserved ? 'S&iacute;' : 'No'; ?>
</td>
</tr>
<!---- ADV ---------------------------router------------------------------------------------------------------------------------------------------------------------------------------->
<TR>
<TH align=center>&nbsp;<?php echo $TbMsg[28]?>&nbsp;</TH>
@ -543,6 +551,7 @@ function TomaPropiedades($cmd,$ida)
global $paginalogin;
global $paginavalidacion;
###################### UHU
global $remotepc_reserved;
$idaula=0;
$nombreaula="";
@ -584,6 +593,7 @@ function TomaPropiedades($cmd,$ida)
$gidperfilhard=0;
$oglive="";
$cntDiff=0;
$remotepc_reserved=0;
$rs=new Recordset;
$cmd->texto="SELECT aulas.*, COUNT(ordenadores.idordenador) AS numordenadores,
@ -646,6 +656,7 @@ function TomaPropiedades($cmd,$ida)
$idordprofesor=$rs->campos["idordprofesor"];
#################### NSA calendarios
$idcalendario=$rs->campos["idcalendario"];
$remotepc_reserved=$rs->campos["remotepc_reserved"];
$ordenadores=$rs->campos["numordenadores"];
$idmenu=$rs->campos["idmenus"];

View File

@ -422,7 +422,7 @@ function og_ordenador_cumple_criterios ($client) {
* @param int building id
* @param int lab id
* @param int image id
* @return int number of clients available for remotepc
* @return int number of clients available for remotepc, -1 if aula is not remote or null on error
*/
function og_sondeoAula ($idCentro, $idAula, $idImagen) {
global $OG_REST_URL;
@ -431,12 +431,12 @@ function og_sondeoAula ($idCentro, $idAula, $idImagen) {
$aula = og_getAula ($idCentro, $idAula);
if (null === $aula || $aula->inremotepc != 1) {
do_log ('lab is null, or not in remotepc, ignoring lab');
return 0;
return -1;
}
if (!og_aula_is_remote ($aula->idcalendario)) {
do_log ('lab is not remote, ignoring lab');
return 0;
return -1;
}
$url = $OG_REST_URL."ous/".$idCentro."/labs/".$idAula."/clients/status";
@ -498,6 +498,51 @@ function og_sondeoAula ($idCentro, $idAula, $idImagen) {
return $clientsOn;
}
/**
* _set_lab_reserved ($idAula)
* @brief Mark lab as reserved or unreserved in the OG DB
* @param int lab id
* @param int reserved (1) or unreserved (0)
* @return bool success (true) or failure (false)
*/
function _set_lab_reserved ($idAula, $reserved) {
global $cnx;
$cmd = CreaComando ($cnx);
if (!$cmd) { die ('ACCESS_ERROR'); }
if ($reserved) {
do_log ("reserving lab $idAula");
} else {
do_log ("unreserving lab $idAula");
}
$cmd->CreaParametro ('@idaula', $idAula, 1);
$cmd->CreaParametro ('@reserved', $reserved, 1);
$cmd->texto = 'UPDATE aulas SET remotepc_reserved=@reserved WHERE idaula=@idaula';
$resul=$cmd->Ejecutar();
$rs->Cerrar();
return $resul;
}
/**
* reserve_lab ($idAula)
* @brief Mark lab as reserved in the OG DB
* @param int lab id
* @return bool success (true) or failure (false)
*/
function reserve_lab ($idAula) {
_set_lab_reserved ($idAula, 1);
}
/**
* unreserve_lab ($idAula)
* @brief Mark lab as unreserved in the OG DB
* @param int lab id
* @return bool success (true) or failure (false)
*/
function unreserve_lab ($idAula) {
_set_lab_reserved ($idAula, 0);
}
$OG_REST_AUTH = db_fetch_apikey();
@ -538,6 +583,9 @@ foreach ($servicePools as $servicePool) {
if (null === $max_srvs) {
do_log ('og_sondeoAula for the OU/lab/image failed, ignoring this service pool');
continue;
} elseif (-1 === $max_srvs) {
unreserve_lab ($service->lab);
continue;
}
$servicePool->osmanager_id = null;
$servicePool->max_srvs = $max_srvs;
@ -556,6 +604,9 @@ foreach ($servicePools as $servicePool) {
do_log ('uds_setServicePool failed');
continue;
}
reserve_lab ($service->lab);
do_log (sprintf ("Service pool '%s': OU id '%d', lab id '%d', image id '%d', max servers '%d', visible '%d'", $sp->name, $service->ou, $service->lab, $service->image, $sp->max_srvs, $sp->visible));
}