Ahahahaahah

ci stai ancora lavorando
Ti posto le tabelle così rendo meglio l'idea
Codice: Seleziona tutto
mysql> select * from trattamento;
+------+-------------------+
| tipo | descrizione |
+------+-------------------+
| 1 | Ricostruzione |
| 2 | Refill |
| 3 | Ricostr. Piedi |
| @ | Tratt Estetico |
| A | Riparazione |
| A2 | Riparazione mani |
| A3 | Riparazione piedi |
| SP | Semipermanente |
| T | Tolte |
| T2 | Tolte mani |
| T3 | Tolte piedi |
| XX | SCONOSCIUTO |
+------+-------------------+
12 rows in set (0.00 sec)
mysql> select * from dipendenti;
+----+-------------+---------+----------+
| id | nome | Cognome | Telefono |
+----+-------------+---------+----------+
| 1 | Sandra | cognome | telefono |
| 2 | Rita | cognome | telefono |
| 3 | Paola | cognome | telefono |
| 4 | Ornella | cognome | telefono |
| 5 | Ester | cognome | telefono |
| 6 | Antonella | cognome | telefono |
| 7 | Daniela V | cognome | telefono |
| 8 | Floriana | cognome | telefono |
| 9 | Claudia | cognome | telefono |
| 10 | Daniela B | cognome | telefono |
| 11 | Denise | cognome | telefono |
| 12 | Bengi | cognome | telefono |
| 13 | Francesca | cognome | telefono |
| 14 | SCONOSCIUTO | cognome | telefono |
| 20 | Grazia | cognome | telefono |
+----+-------------+---------+----------+
15 rows in set (0.00 sec)
Dove l'appuntamento è formato da
giorno.mese.anno-trattamento1-trattamento2.....-trattamentoN ( dipendente )
Per quanto sia contorta
questa è la mia soluzione
Codice: Seleziona tutto
<?php
//CONNETTO A MYSQL
if (!($mylink = mysql_connect("localhost","root","")))
{
print "<h3>Non riesco a collegarmi a mysql, modifica connessione.php</h3>\n";
exit;
}
mysql_select_db("AGENDASASSARI");// or die "Non riesco a selezionare il database";
$nomefile="sassari.vcf";
/* mysql_select_db("AGENDAPTORRES");
$nomefile="ptorres.vcf";
mysql_select_db("AGENDASORSO");
$nomefile="sorso.vcf";
*/
$elimina_appuntamenti=mysql_query("delete from appuntamenti;");
if($elimina_appuntamenti==FALSE) print "Non riesco ad eliminare i vecchi appuntamenti!".mysql_error();
$elimina_clienti=mysql_query("delete from clienti;");
if($elimina_clienti==FALSE) print "Non riesco ad eliminare i vecchi clienti!".mysql_error();
$idcliente="";
$file = fopen("$nomefile", "r" )or die ("Non posso aprire il file \n");
$stato = 0;
while (! feof($file))
{
$riga=preg_replace('/[[:space:]]+/', ' ', fgets($file, 1024));
//TRASFORMO RIGA IN MAIUSCOLO
$riga= strtoupper($riga);
//$riga= str_replace("'","",$riga);
$show=0;
if ( substr($riga,0,2) == "FN")
$stato=1;
elseif (substr($riga,0,3) == "TEL")
$stato=2;
elseif ( substr($riga,0,4) == "NOTE")
$stato=3;
elseif ( substr($riga,0,3) == "END")
$stato=4;
elseif (($stato != 3)||($stato == 0) )
continue;
switch($stato)
{
case 1:
$nome_cognome=substr($riga, 3);
$nome_cognome=str_replace("'","",$nome_cognome);
$nome_array = explode(" ", $nome_cognome);
if(isset($nome_array[3]))
{
$nome_array[0]=$nome_array[0]."".$nome_array[1];
$nome_array[2]=$nome_array[3];
}
if ($nome_array[0] == "") $nome_array[0] = "Sconosciuto";
if ($nome_array[1] == "") $nome_array[1] = "Sconosciuto";
$stato=0;
break;
case 2:
$telefono= substr($riga,14);
//print "<BR><h3>$nome_array[0] $nome_array[1]</h3>";
/*
$stringaclienti="INSERT INTO clienti VALUES (NULL, '$nome_array[0]','$nome_array[1]','$telefono', NULL);";
db_clienti($stringaclienti);
$idcliente=mysql_insert_id();
*/
//print "<BR><FONT color=GREEN>Ultimo ID cliente inserito = $idcliente</FONT>";
$stato=0;
break;
case 3:
if(isset($note)) $note= $note."".$riga;
else $note=substr($riga,5);
break;
case 4:
if(!isset($note))
{
$stato=0;
continue;
}
//INSERISCO QUÌ IL CLIENTE, SOLO SE CI SONO APPUNTAMENTI
$stringaclienti="INSERT INTO clienti VALUES (NULL, '$nome_array[0]','$nome_array[1]','$telefono', NULL, NULL);";
db_clienti($stringaclienti);
$idcliente=mysql_insert_id();
//Divido ogni singolo appuntamento
$appuntamenti = explode("\"", $note);
if(count($appuntamenti) < 1)
{
$stato=0;
continue;
}
for($j=0;$j<count($appuntamenti);$j++)
{
controlla_appuntamento($appuntamenti[$j]);
}
if(preg_match("*:*",$note))
{
$note=@explode(":",$note);
aggiornainfocliente($note);
}
$stato=0;
unset($note);unset($nome_array);unset($data);unset($appuntamenti);
break;
}//FINE SWITCH
}//FINE LEGGI-RIGA
?>
<?php
function controlla_appuntamento($appuntamento)
{
global $idcliente;
//Elimino gli spazi:
$appuntamento=str_replace(" ", "", $appuntamento);
//verifico se no show e metto 1 se cè
if(preg_match("/show/i",$appuntamento)) $show=1;
else $show=0;
$s_appunt=explode(")", $appuntamento);
//Esempio $s_appunt[0] => 16.11.10-2(4 => 21.05.11-2-5-2-3(3
$info= explode("-",$s_appunt[0]);
//Formo la data
$data=$info[0]; //INFO[0] CONTIENE DATA
//ELIMINO LETTERE BACKSLASH E ' :'
$data=ereg_replace("[A-Z]","",$data);
$data=str_replace("\\","",$data);
$data=str_replace("\/","",$data);
$data=str_replace(":","",$data);
$data=explode(".",$data);
if( isset($v_data[0]) && isset($v_data[1]) && isset($v_data[2]) )
$data=controlladata($data);
//else break;
//Trovo tutti i trattamenti per questo appuntamento
//da INFO[1] a INFO[FINE]
for($i=count($info)-1;$i>0;$i--)
{
if(@preg_match("*\(*", $info[$i]))
{
//print "<BR>TROVO: $info[$i]<BR>";
$divisione=explode("(",$info[$i]);
$dipendente= $divisione[1];
$dipendente=controlladipendente($dipendente);
$prestazione= $divisione[0];
$prestazione=controllaprestazione($prestazione);
@$stringaappuntamenti="INSERT INTO appuntamenti VALUES ( null , '20$data[2]-$data[1]-$data[0] 10:00:00', '$s_appunt[0]', $idcliente, $dipendente, '$prestazione',$show);";
db_trattamenti($stringaappuntamenti);
}else
{
$prestazione=$info[$i];
$prestazione=controllaprestazione($prestazione);
@$stringaappuntamenti="INSERT INTO appuntamenti VALUES ( null , '20$data[2]-$data[1]-$data[0] 10:00:00', '$s_appunt[0]', $idcliente, $dipendente, '$prestazione',$show);";
db_trattamenti($stringaappuntamenti);
}
}
}
function aggiornainfocliente($x)
{
global $idcliente;
$infocliente="";
for ($i=1;$i<count($x);$i++)
{
if(isset($infocliente)) $infocliente= $infocliente."".$x[$i];
else $infocliente=$x[$i];
}
$infocliente=str_replace("\"","",$infocliente);
$aggiornainfo="update clienti set info = \"$infocliente\" where id=$idcliente";
if( mysql_query($aggiornainfo)==FALSE)
{
print "ERRORE INFO CLIENTE $idcliente \t ESPRESSIONE: $aggiornainfo \n \n";
}
}
function controlladata($v_data)
{
global $nome_array;
if(! isset($v_data[0])) //SE GIORNO NON PRESENTE
$v_data[0]=1;
if(! isset($v_data[1])) //SE MESE NON PRESENTE
$v_data[1]=1;
if(! isset($v_data[2])) //SE ANNO NON PRESENTE
$v_data[2]=50;
if(checkdate($v_data[1],$v_data[0],"20".$v_data[2]) == FALSE)
print "CLIENTE: $nome_array[0] $nome_array[1] data \"$v_data[0],$v_data[1],20.$v_data[2]\" non valida \n";
return($v_data);
}
function controlladipendente($x)
{
//AGGIUNGERE SE CE UN NUMERO CONTROLLA SE +DI 14+
if ($x=='A')
{
$x="6";
return($x);
}elseif ($x=='B')
{
$x="12";
return($x);
}else
if(@preg_match("/[A-Z]/",$x)) $x="14";
elseif( (int)$x > 13) $x=14;
return ($x);
}
function controllaprestazione($prestazione)
{
if (($prestazione == "1" ) || ($prestazione == "2" ) ||($prestazione == "3" ) || ($prestazione == "@" ) || ($prestazione == "A" ) || ($prestazione == "A2" ) || ($prestazione == "A3" ) || ($prestazione == "SP" ) || ($prestazione == "T" ) || ($prestazione == "T2" ) || ($prestazione == "T3" ) )
return($prestazione);
elseif($prestazione == "3T") $prestazione="T3";
else $prestazione="XX"; //Per tutti i caratteri non in trattamenti
return($prestazione);
}
function db_clienti($query)
{
//print "<BR> Query arrivata: \t $query <BR>";
if(mysql_query($query) == FALSE)
{
print "ERRORE INSERIMENTO CLIENTE \t \t '$query' \n \n";//.mysql_error();
}
//else print "<BR>OK APPUNTAMENTO \t '$query' ";
}
function db_trattamenti($query)
{
if(mysql_query($query) == FALSE)
{
global $j;
global $appuntamenti;
global $nome_array;
print "ERRORE APPUNTAMENTO di |$nome_array[0] - $nome_array[1]| \t ESPRESSIONE ARRIVATA: $appuntamenti[$j]\n"; ;// \t '$query' <br></font>";//.mysql_error();
//print "Query arrivata: \t $query \n \n";
}
//else print print "<BR>OK APPUNTAMENTO \t '$query' ";
}
?>
Quindi credi sia possibile fare tutto in una istruzione?