-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass_.php
421 lines (232 loc) · 7.94 KB
/
class_.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php
// LA CONNESSIONE
function conntrue(){
$my = new mysqli("localhost", "root", "new-password","test");
return $my ;
}
class contatti{
var $nome;
var $cognome;
var $email;
var $azienda;
var $telefono;
var $sito;
public function __construct (){
/*$nome,$cognome,$email,$azienda,$telefono,$sito
$this->nome=$nome;
$this->cognome=$cognome;
$this->email=$email;
$this->azienda=$azienda;
$this->telefono=$telefono;
$this->sito=$sito;
*
*
*/
}
public function form(){
// STAMPO TUTTI GLI UTENTI INTERNI tagliando le iniziali della parola segreta
$prova=new utenti();$prova->trovatuttiutenti();
?>
<form id='userpersonal' onsubmit='return false;' >
<input type='text' name='credenziale' class='credenziale'>
<label></label>
</form>
<form id='formcont' onsubmit='return false;'>
nome:
<input type="text" id='nome' onkeyup="cntr(this)" name='nome' >
cognome:
<input type="text" onkeyup="cntr(this)" name='cognome' id='cognome'>
email:
<input type="text" onkeyup="cntr(this)" name='email' id='email'>
azienda:
<input type="text" onkeyup="cntr(this)" name='azienda' id='azienda'>
telefono:
<input type="text" onkeyup="cntr(this)" name='telefono' id='telefono'>
sito:
<input type="text" onkeyup="cntr(this)" name='sito' id='sito'>
<input type="button" class="invia" value="registra" />
<input type="button" class="vedirisult" value="Open" />
<input type='button' class='hideresult' value='Closer' />
</form>
<form id='trova' onsubmit="return false;">
<input type='text' id='trovanome' name='trovanome'/>
</form>
<?
}
//STAMPO AL VOLO TUTTO
public function printresult($idutente,$nome){
$my=conntrue();
// $my = new mysqli("localhost", "root", "new-password","test");
$sql="SELECT * from contact where id_exutente = $idutente ";
// SINGOLO SOLO NOME
if($nome != ""){
$sql.= " and nome LIKE '%$nome%' ";
}
$sql.="order by id_contact desc limit 0,200 ";
$result= $my -> query ($sql);
echo "<table border='1' style='width:100%;'><thead><th>nome</th>
<th>cognome</th><th>email</th><th>azienda </th>
<th>telefono</th>
<th>sito </th> <th>Inserito </th>
</thead><tbody>";
while ($ris=mysqli_fetch_assoc($result)){
extract($ris);
$dint = date('d-m-Y h:i:s',($datainsert));
echo "<tr><td>$nome</td>
<td>$cognome</td>
<td>$email</td>
<td>$azienda</td>
<td>$telefono</td>
<td>$sito</td> <td> $dint</td></tr> " ;
}
echo "</tbody></table>";
}
// INSERISCI
public function insertdb($array){
$id= $_SESSION['id_utente'];
$datain=strtotime(date('d-m-Y h:i:s') );
foreach($array as $v => $names){$lorifo.= $v.'='.$names.'&';}
parse_str($lorifo);
$my=conntrue();
$sql="INSERT into contact values(null,'$nome','$cognome','$email','$azienda','$telefono','$sito','$id','$datain' ) ";
$result= $my -> query ($sql);
print_r($lorifo);
}
//function trova da fare
public function trova($arraydaform){
$my=conntrue();
$sql="SELECT * FROM contact ";
$result= $my -> query ($sql);
while($row= mysqli_fetch_assoc($result)){
echo "<pre>";
print_r ($row);
echo "<pre>";
}
}
//FINE CLASSE CONTATTI
}
/** UTENTI VOLANTI AL VOLO ..............
* utenti per log volanti gemellati alla lista dei contatti
*/
class utenti {
var $mycooker;
var $email;
function __construct() {
}
// QUI MI INCASINO SEMPRE + credo di farla semplice + la incasino
function trovasesiste($mycooker,$email){
// QUI ERA NATO PERIL COOKIE INVECE PASSO LA SESSION
$my=conntrue();
$sql='SELECT * from utenti where ';
// se passo il cookie
// se il cooki o sessione che passo è presente nel DB
if ($mycooker !=""){
$sql.= "mycooker ='$mycooker' " ;
$result= $my -> query ($sql);
}
// $email Sarebbe il nome che l utente posta per fare login
// QUI MI POPOLA SE CLICKKA UN NUOVO ENTRATO O SE IL NOME esiste nel DB
if ($email !=""){
$sql.= "email='$email' " ;
$result= $my -> query ($sql);
// Se il nome non esiste
if($row= mysqli_num_rows($result) == 0){
?>
<script>
var newcl="Attenzione utente assente --Crearlo - <a href='' onclick='return false;' class='newcl' >Si creo-- (<?php echo $email;?>)</a>" ;
$('#userpersonal label').html(newcl);
function confermanew(){
$('.newcl').click( function (){
$('#userpersonal label').html("ATTENDERE ......");
$.post("control.php",{"confermautente":"yes","nomeperinsert":"<?php echo $email ;?>"}).done(function(data){
location.reload();
});
});};
confermanew();
</script>
<?php
exit ;
}
}
//$result= $my -> query ($sql);
// QUI PASSA SE L UTENTE ESISTE DA NOME O DA COOKIE ;; O SESSIONE AL MOMENT
if($row= mysqli_num_rows($result) > 0 ){
$risult=mysqli_fetch_array($result);
// QUI MI PRENDO L ID DELL UTNTE CHE FA LOGIN
$_SESSION['id_utente']=$risult['id_utente'];
$cook=session_id();
$sqlupdatecook ="UPDATE utenti set mycooker='$cook' where id_utente='$_SESSION[id_utente]' ";
$resultupdate = $my -> query ($sqlupdatecook);
?>
<script type='text/javascript'>
var c = $('.credenziale').val("<?php echo $risult['email'];?>" );
$('#userpersonal input ').hide("slow");
var out="<span class='output' style='color:red;padding-left:19px;cursor:pointer;' >Logout</span>";
$('#userpersonal label').html("Utente Loggato come : <span style='color:green'>"+ c.val() +"</span>"+ out );
$('.output').click(function() {
$.post("control.php",{"logout":"on"}).done(function(){
location.reload();
// $('#formcont').fadeOut('slow');
// $('#userpersonal').fadeIn("slow");
})
});
//SE è loggato passa e si vede il form
$('#formcont').fadeIn('slow');
</script>
<?php
}else{
// FINO A QUANDO NON OTTENGO un nome
?><script>
$('#formcont').hide('slow');
// VABBE LASCIAMO STARE non va bene ma va molto meglio
function login(){
var c= $('.credenziale').val();
$('.credenziale').focus();
$('#userpersonal label').html("Login o scegli una password ");
// Key up è sbagliato per l uso che ne servirebbe sarebbe meglio un set timeou ..
$('.credenziale').keyup(function(){
var c=$(this).val();
if(c.length > 6 ){
$($('.credenziale')).css({"border":"4px solid green"});
$('#userpersonal label').html("<p class='insertutente' style='cursor:pointer;'>Entra e/o Registrati </p> ");
// SE avviene un insert new utente
$('.insertutente').click(function(){
$("#userpersonal label").html("attendere ...");
$.post("control.php",{'newclient':c }).done(function(data){
$("#userpersonal label").html(data);
});
});
// $('#userpersonal input ').hide("slow");
}else{
var count = c.length - 7;
$($('.credenziale')).css({"border":"14px solid red"});
$('#userpersonal label').html("Scrivi altri "+ count );
$('#formcont').hide('slow');
}
});
}
login();
</script>
<?php
}
}
function trovatuttiutenti(){
$my=conntrue();
$sql="SELECT * from utenti order by id_utente desc limit 0,1000";
$result= $my -> query ($sql);
echo "utenti :(".mysqli_num_rows($result).')-->';
while($row=mysqli_fetch_assoc($result)){
$names=substr_replace($row['email'],'..',0,2);
echo $names .'-';
}
}
function insertutente( $mycooker,$email){
$my=conntrue();
$sql="INSERT into utenti values (null,'$email','$mycooker') ";
$result= $my -> query ($sql);
if($result){
sleep(2);
}else{echo mysqli_error(); }
}
}
?>