PDA

View Full Version : [php] turno lavoratori


zebmckey
28-04-2016, 09:35
Salve gente,
vorrei creare un programmino che mi dia la possibilità di fare i servizi. Vorrei che le persone vengano inserite nei turni in base al giorno della settimana. Mi spiego: i turni sono: feriali (dal lunedi al giovedi), turno del venerdi, turno del sabato, turno festivo. Chiaramente le persone vanno inserite per anzianità, e tra un servizio ed un'altro devono passare 4 giorni almeno.
Le tabelle le ho già fatte, il form per inserite gli utenti che faranno i servizi anche. Mi sono bloccato su come fare:
1 - creare la suddivisone delle date;
2 - creare la query che mi da come risultato la persona che monta quel giorno.
Chi avesse voglia di darmi un'aiuto possiamo creare un gruppo di lavoro. posso rendere tutto disponibile e sarà tutto opensource.
Grazie

zebmckey
02-05-2016, 14:39
Chiedo scusa se solo oggi mi faccio risentire, ma per problemi non mi è stato possibile.
Il sistema è su Centos 6
httpd-2.2.15-47.el6.centos.4.x86_64
mysql-5.1.73-5.el6_7.1.x86_64
php-5.3.3-46.el6_7.1.x86_64

di seguito il database

-- MySQL dump 10.13 Distrib 5.1.73, for redhat-linux-gnu (x86_64)
--
-- Host: localhost Database: servizi
-- ------------------------------------------------------
-- Server version 5.1.73

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `assenze`
--

DROP TABLE IF EXISTS `assenze`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `assenze` (
`id_assenza` int(11) NOT NULL AUTO_INCREMENT,
`id_utente` int(11) NOT NULL,
`tipo` varchar(45) DEFAULT NULL,
`data_da` date DEFAULT NULL,
`data_al` date DEFAULT NULL,
PRIMARY KEY (`id_assenza`),
KEY `utente_ind` (`id_utente`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `assenze`
--

LOCK TABLES `assenze` WRITE;
/*!40000 ALTER TABLE `assenze` DISABLE KEYS */;
/*!40000 ALTER TABLE `assenze` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `grado`
--

DROP TABLE IF EXISTS `grado`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `grado` (
`id_grado` int(11) NOT NULL AUTO_INCREMENT,
`grado` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id_grado`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `grado`
--

LOCK TABLES `grado` WRITE;
/*!40000 ALTER TABLE `grado` DISABLE KEYS */;
/*!40000 ALTER TABLE `grado` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `recupero`
--

DROP TABLE IF EXISTS `recupero`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `recupero` (
`id_recupero` int(11) NOT NULL AUTO_INCREMENT,
`id_grado` int(11) NOT NULL,
`id_utente` int(11) NOT NULL,
`id_servizio` int(11) NOT NULL,
`dataservizio` date DEFAULT NULL,
PRIMARY KEY (`id_recupero`),
KEY `utente_ind` (`id_utente`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `recupero`
--

LOCK TABLES `recupero` WRITE;
/*!40000 ALTER TABLE `recupero` DISABLE KEYS */;
/*!40000 ALTER TABLE `recupero` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tipo_servizio`
--

DROP TABLE IF EXISTS `tipo_servizio`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tipo_servizio` (
`id_servizio` int(11) NOT NULL AUTO_INCREMENT,
`servizio` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id_servizio`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tipo_servizio`
--

LOCK TABLES `tipo_servizio` WRITE;
/*!40000 ALTER TABLE `tipo_servizio` DISABLE KEYS */;
/*!40000 ALTER TABLE `tipo_servizio` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `turno1fes`
--

DROP TABLE IF EXISTS `turno1fes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `turno1fes` (
`id_t1` int(11) NOT NULL AUTO_INCREMENT,
`id_grado` int(11) NOT NULL,
`id_utente` int(11) NOT NULL,
`id_servizio` int(11) NOT NULL,
`data` date DEFAULT NULL,
PRIMARY KEY (`id_t1`),
KEY `utente_ind` (`id_utente`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `turno1fes`
--

LOCK TABLES `turno1fes` WRITE;
/*!40000 ALTER TABLE `turno1fes` DISABLE KEYS */;
/*!40000 ALTER TABLE `turno1fes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `turno2PF`
--

DROP TABLE IF EXISTS `turno2PF`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `turno2PF` (
`id_t2` int(11) NOT NULL AUTO_INCREMENT,
`id_grado` int(11) NOT NULL,
`id_utente` int(11) NOT NULL,
`id_servizio` int(11) NOT NULL,
`data` date DEFAULT NULL,
PRIMARY KEY (`id_t2`),
KEY `utente_ind` (`id_utente`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `turno2PF`
--

LOCK TABLES `turno2PF` WRITE;
/*!40000 ALTER TABLE `turno2PF` DISABLE KEYS */;
/*!40000 ALTER TABLE `turno2PF` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `turno3V`
--

DROP TABLE IF EXISTS `turno3V`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `turno3V` (
`id_t3` int(11) NOT NULL AUTO_INCREMENT,
`id_grado` int(11) NOT NULL,
`id_utente` int(11) NOT NULL,
`id_servizio` int(11) NOT NULL,
`data` date DEFAULT NULL,
PRIMARY KEY (`id_t3`),
KEY `utente_ind` (`id_utente`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `turno3V`
--

LOCK TABLES `turno3V` WRITE;
/*!40000 ALTER TABLE `turno3V` DISABLE KEYS */;
/*!40000 ALTER TABLE `turno3V` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `turno4fer`
--

DROP TABLE IF EXISTS `turno4fer`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `turno4fer` (
`id_t4` int(11) NOT NULL AUTO_INCREMENT,
`id_grado` int(11) NOT NULL,
`id_utente` int(11) NOT NULL,
`id_servizio` int(11) NOT NULL,
`data` date DEFAULT NULL,
PRIMARY KEY (`id_t4`),
KEY `utente_ind` (`id_utente`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `turno4fer`
--

LOCK TABLES `turno4fer` WRITE;
/*!40000 ALTER TABLE `turno4fer` DISABLE KEYS */;
/*!40000 ALTER TABLE `turno4fer` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `turno5SF`
--

DROP TABLE IF EXISTS `turno5SF`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `turno5SF` (
`id_t5` int(11) NOT NULL AUTO_INCREMENT,
`id_grado` int(11) NOT NULL,
`id_utente` int(11) NOT NULL,
`id_servizio` int(11) NOT NULL,
`data` date DEFAULT NULL,
PRIMARY KEY (`id_t5`),
KEY `utente_ind` (`id_utente`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `turno5SF`
--

LOCK TABLES `turno5SF` WRITE;
/*!40000 ALTER TABLE `turno5SF` DISABLE KEYS */;
/*!40000 ALTER TABLE `turno5SF` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `utente`
--

DROP TABLE IF EXISTS `utente`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `utente` (
`id_utente` int(11) NOT NULL AUTO_INCREMENT,
`id_grado` int(11) NOT NULL,
`cognome` varchar(45) DEFAULT NULL,
`nome` varchar(45) DEFAULT NULL,
`anzianita` date NOT NULL,
`id_servizio` int(11) NOT NULL,
PRIMARY KEY (`id_utente`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `utente`
--

LOCK TABLES `utente` WRITE;
/*!40000 ALTER TABLE `utente` DISABLE KEYS */;
/*!40000 ALTER TABLE `utente` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2016-05-02 13:49:58



al momento ho fatto solo i file per l'inserimento del personale
Le tabelle grado e servizio le devo ancora popolare.


<html>
<body>
<table width="420" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="personale_form" method="post" action="act_utente.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFDEAD">

<tr>
<td colspan="4" style="text-align:center"><strong>Inserimento Dati </strong></td>
</tr>

<tr>
<td>Grado</td>
<td>:</td>
<td style="width: 279px"><select name="mod_grado" >
<option value="000" selected="selected">[Seleziona]</option>
<optgroup label="Ufficiali">
<option value="1">Gen.C.A. </option>
<option value="2">Gen.Div. </option>
<option value="3">Gen.B. </option>
<option value="4">Col. </option>
<option value="5">Ten.Col. </option>
<option value="6">Magg. </option>
<option value="7">Cap. </option>
<option value="8">Ten. </option>
<option value="9">S.Ten. </option>
<optgroup label="Marescialli">
<option value="10">1&deg Mar.Luogt. </option>
<option value="11">1&deg Mar. </option>
<option value="12">Mar.Ca. </option>
<option value="13">Mar.Ord. </option>
<option value="14">Mar. </option>
<optgroup label="Sergenti">
<option value="15">Serg.Magg.Ca. </option>
<option value="16">Serg. Magg. </option>
<option value="17">Serg. </option>
<optgroup label="Truppa">
<option value="18">C.le Magg.Ca.Sc. </option>
<option value="19">C.le Magg.Ca. </option>
<option value="20">C.le Magg.Sc. </option>
<option value="21">1&deg C.le Magg. </option>
<option value="22">C.le Magg. </option>
<option value="23">C.le </option>
</select>&nbsp;
</td>
</tr>


<tr>
<td>Cognome</td>
<td>:</td>
<td style="width: 279px"><input name="mod_cognome" type="text" id="mod_cognome">&nbsp;
</td>
</tr>

<tr>
<td>Nome</td>
<td>:</td>
<td style="width: 279px"><input name="mod_nome" type="text" id="mod_nome">&nbsp;
</td>
</tr>
<tr>
<td>Anzianita'</td>
<td>:</td>
<td style="width: 279px"><input name="mod_anz" type="data" id="mod_anz">&nbsp;
</td>
</tr>

<tr>
<td>Servizio</td>
<td>:</td>
<td style="width: 279px"><select name="mod_serv" >
<option value="000" selected="selected">[Seleziona]</option>
<option value="1">Ufficiale di ispezione</option>
<option value="2">Ufficiale di picchetto</option>
<option value="3">Sottufficiale di ispezione </option>
<option value="4">Comandante della guardia</option>
</select>&nbsp;
</td>
</tr>

<td>&nbsp;</td>
<td>&nbsp;</td>
<td style="width: 279px" class="style1"><input type="submit" name="Submit" value="Inserisci"></td>
<td>&nbsp;</td>
</tr>
</table>
</table>
<br>
<br>

</body>
</html>




<?php
include("dati.txt");
//variabili
$grado=$_POST['mod_grado'];
$cognome=$_POST['mod_cognome'];
$cognome=strtoupper($cognome);
$nome=$_POST['mod_nome'];
$nome=strtoupper($nome);
$anz=$_POST['mod_anz']
$servizio=$_POST['mod_serv']

$link=mysql_connect("$db_host","$db_login","$db_pass") or die ("Non riesco a connettermi a $db_host");

mysql_select_db ($database, $link)
or die ("Non riesco a selezionare il db $database<br>");

$pers="INSERT INTO utente (id_utente, id_grado, cognome, nome) VALUES ('', '$grado', '$cognome', '$nome', '$anz', '$servizio')";
mysql_query ($pers, $link)
or die ("Non riesco ad eseguire la query $pers");

Echo "I Dati sono stati archiviati con successo nel DataBase $database";
mysql_close ($link);
?>



adesso in base al personale che inserirò devo creare una query che rispetti alcuni parametri, che sono:
1. chi non ha effettuato il servizio
2. tra chi non è montato mi dia un'ordine in base all'anzinità
3. se la data è festiva dal più anziano al più giovane, se feriale dal più giovane al più anziano.
La vedo dura intanto vado avanti e man mano metterò i vari aggiornamenti.
Grazie

les2
02-05-2016, 15:20
ciao, ora è più facile poterti aiutare :)

di dove sei?
(se fossimo vicini diventerebbe ancora più facile)

Ciao

les2
02-05-2016, 15:21
hai già fatto un'analisi del tutto?
perchè noi sicuramente ti proporremmo soluzioni leggermente diverse ;)

zebmckey
02-05-2016, 22:42
hai già fatto un'analisi del tutto?
perchè noi sicuramente ti proporremmo soluzioni leggermente diverse ;)

Io sono di Treviso. Se avete idee diverse ben vengano sviluppiamole insieme ;)

zebmckey
03-05-2016, 13:13
Ho apprtato degli aggiornamenti nel file sql , chiaramente ho dovuto modificare anche i file html e php.
turni-di-lavoro su github (https://github.com/zebmckey/turni-di-lavoro)

zebmckey
24-05-2016, 07:59
Continuo con il mio lavoretto ,anche se purtroppo a singhiozzi per carico lavorativo.
non riesco a risolvere un piccolo problema

// Gestione dell'output dati
echo "<table border=1>
<tr><td>ID</td>
<td>Grado</td>
<td>Cognome</td>
<td>Nome</td>
<td>Data di Nascita </td>
<td>Anzianita di grado</td>
<td>Servizio</td>
<td>Stato</td></tr>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$ID = $row["id_utente"];
$grado = $row["grado"];
$cognome = $row["cognome"];
$nome = $row["nome"];
$data_nascita = $row["data_nascita"];
$anzianita = $row["anzianita"];
$servizio = $row["servizio"];
$esente = $row["esente"];
echo "<tr>";
echo "<td>$ID</td>";
echo "<td>$grado</td>";
echo "<td>$cognome</td>";
echo "<td>$nome</td>";
echo "<td>$data_nascita</td>";
echo "<td>$anzianita</td>";
echo "<td>$servizio</td>";
// echo "<td>$esente</td>";
if $esente=='A'{
echo ('<td><a href="motivoassenza.php?id=' . $ID . '">' . $esente . '</a></td>');
else $esente=='P'
echo "<td>$esente</td>";
}
echo "</tr>";
}

echo "</table>";


Vorrei che la variabile $esente sia visibile come collegamento solo se è uguale ad "A" se invece è "P" deve rimanere normale senza nessun link.
Chiaramente il codice sopra non funziona. Come posso fare?

zebmckey
24-05-2016, 08:22
Ok risolto!

// echo "<td>$esente</td>";
if ($esente == A){
echo ('<td><a href="motivoassenza.php?id=' . $ID . '">' . $esente . '</a></td>');
}
/*else ($esente == P){
echo "<td>$esente</td>";
}
*/ echo "</tr>";
}



togliendo "else" mi appare solo se il risultato della variabile è = ad "A" con il relativo link.
Questa può essere una soluzione. Se riesco a vedere anche la "P" non sarebbe male.

les2
25-05-2016, 14:50
ciao Zeb, scusa il ritardo non ti ho più filato :)
riprendo il tuo precedente commento (stai sbagliando un pelo la sintassi):


if ('A'==$esente) {
echo ('<td><a href="motivoassenza.php?id=' . $ID . '">' . $esente . '</a></td>');
} else if ('P'==$esente) {
echo "<td>$esente</td>";
}


e attento alle parentesi, chiudile in line dove le apri altrimenti non si capisce ;)

zebmckey
26-05-2016, 09:16
Grazieee, porca pupazza che errore da pivello :mc: :mc: :muro: :muro: :muro:

ciao Zeb, scusa il ritardo non ti ho più filato :)
riprendo il tuo precedente commento (stai sbagliando un pelo la sintassi):


if ('A'==$esente) {
echo ('<td><a href="motivoassenza.php?id=' . $ID . '">' . $esente . '</a></td>');
} else if ('P'==$esente) {
echo "<td>$esente</td>";
}


e attento alle parentesi, chiudile in line dove le apri altrimenti non si capisce ;)