-
Notifications
You must be signed in to change notification settings - Fork 2
/
form_member.php
599 lines (552 loc) · 19.4 KB
/
form_member.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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
<?php
// Funciones de conexión con la base de dato
require 'funciones.php';
require('clases/fpdf.php');
define('FPDF_FONTPATH','font/');
require('clases/rpdf.php');
require('funciones/rounded_rect2.php');
//error_reporting(E_ALL);
$link = conectar();
session_start();
seguridad();
/*
echo "<pre>";
echo var_dump($_SESSION);
echo "</pre>";
*/
/*
echo "<pre>";
echo var_dump($_POST);
echo "</pre>";
*/
if(isset($_POST) && $_POST['sendform']!=''){
$link = conectar();
reset ($_POST);
while (list ($param, $val) = each ($_POST)) {
$asignacion = "\$" . $param . "=$link->real_escape_string(\$_POST['" . $param . "']);";
eval($asignacion);
}
$renewal = str_replace('/','-',$renewal);
if($type != '2' && $type != '5'){
$intitution = '';
$address = '';
$postal_code = '';
$vat = '';
}
$sql = "INSERT INTO members (name,surname,country,language,phone,email,renewal,quota,type,comment,status,date_arrival,institution,address,postal_code,vat) VALUES ('".$name."','".$surname."','".$country."','".$language."','".$phone."','".$email."','".date("Y-m-d",strtotime($renewal))."','".$quota."','".$type."','".$comment."','".$status."','".date("Y-m-d")."','".$institution."','".$address."','".$postal_code."','".$vat."');";
$result = $link->query($sql);
if (!$result) {
die('Invalid query: Problems to insert data into the member table ' . $link->error);
}
$sql = "SELECT max(cod) FROM members;";
$result = $link->query($sql);
$tmp_result = $result->fetch_assoc();
$cod_max = $tmp_result['max(cod)'];
/********************************************************************************************************/
/* GENERAR PDF PARA ADJUNTAR */
/********************************************************************************************************/
if($send_invoice =="YES"){
$link = conectar2();
$sql = "SELECT body, footer, show_signature FROM invoice WHERE cod='1';";
$result_pdf = $link->query($sql);
$aux = $result_pdf->fetch_assoc();
$message = $aux['body'];
$footer = quitar_html($aux['footer']);
$show_signature = ($aux['show_signature']=="YES")?(true):(false);
$sql = "SELECT * FROM members WHERE cod='".$cod_max."';";
$result_pdf = $link->query($sql);
$fila = $result_pdf->fetch_assoc();
$sql = "DESCRIBE members";
$r_campos = $link->query($sql);
$message = quitar_html($message);
while($aux = $r_campos->fetch_assoc()){
if($aux['Field']=="renewal"){
$message = str_replace("{{".$aux['Field']."}}", date("d/m/Y",strtotime($fila[$aux['Field']])), $message);
}elseif($aux['Field']=="quota"){
$message = str_replace("{{".$aux['Field']."}}", (number_format($fila[$aux['Field']],2 , "," ,".").' €'), $message);
}elseif($aux['Field']=="date_arrival"){
$message = str_replace("{{".$aux['Field']."}}", date("d/m/Y",strtotime($fila[$aux['Field']])), $message);
}elseif($aux['Field']=="language"){
$tmp_language = obtener('language','cod',$fila[$aux['Field']],'language');
$message = str_replace("{{".$aux['Field']."}}", $tmp_language, $message);
}elseif($aux['Field']=="type"){
$tmp_type = obtener('type_member','cod',$fila[$aux['Field']],'name');
$message = str_replace("{{".$aux['Field']."}}", $tmp_type, $message);
}elseif($aux['Field']=="status"){
$tmp_status = obtener('status','cod',$fila[$aux['Field']],'status');
$message = str_replace("{{".$aux['Field']."}}", $tmp_status, $message);
}elseif($aux['Field']=="country"){
$tmp_country = obtener('country','iso',$fila[$aux['Field']],'printable_name');
$message = str_replace("{{".$aux['Field']."}}", $tmp_country, $message);
}else{
$message = str_replace("{{".$aux['Field']."}}", $fila[$aux['Field']], $message);
}
}
//echo $message;
$year = date("Y");
$sql = "SELECT max(num_invoice) AS num_invoice FROM invoices WHERE year='".$year."';";
$result = $link->query($sql);
$aux_invoice = $result->fetch_assoc();
$num_invoice = ($aux_invoice['num_invoice']=='NULL')?('1'):($aux_invoice['num_invoice']+1);
$sql = "INSERT INTO invoices (num_invoice,year,cod_member,message,quota,date) VALUES ('".$num_invoice."','".$year."','".$cod_max."','".$link->real_escape_string($message)."','".$fila['quota']."','".date("Y-m-d")."');";
$result = $link->query($sql);
if (!$result) {
die('Invalid query 1: ' . $link->error);
}
//Crear el pdf que se enviará.
class NPDF extends PDF{
//Cabecera de página
function Header(){
//Logo
//$this->Image('imagenes/nsr-proyectos.jpg',20,12,90);
}
//Pie de página
function Footer(){
$this->SetY(-20);
$this->SetTextColor(0, 106, 157);
$this->Ln(3);
$this->SetFont('helvetica','',8);
$this->Cell(170,4,$footer,0,1,'C');
$this->Cell(0,4,'P'.html_entity_decode("á").'gina '.$this->PageNo().'/{nb}',0,0,'R');
}
}
$pdf=new NPDF('P','mm','A4');
$pdf->SetMargins(20,24);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('arial','B',9);
$pdf->SetAutoPageBreak(35,2);
//$pdf->image('imagenes/nosolored_fraSL.jpg',20,10);
$pdf->Image('images/pdf_invoices/logo.png',20,12,90);
$pdf->Ln(2);
$pdf->SetFont('','B','10');
$pdf->Cell(0,4,'N'. html_entity_decode("°").' invoice: '.completar($num_invoice,4)."/".$year,0,0,'R');// Variable
$pdf->SetTextColor(0, 106, 157);
$pdf->Ln(20);
$pdf->SetFont('helvetica','',8);
$pdf->MultiCell(0,4,iconv('UTF-8', 'windows-1252', $message));
if($show_signature){
$pdf->Image('images/pdf_invoices/firma.png');
$pdf->SetFont('','',7);
$pdf->TextWithDirection(12,200,$txtreg,'U');
}
$pdf->Ln(10);
$pdf->MultiCell(0,4,$footer);
$file="invoice".$year."-".completar($num_invoice,4).".pdf";
$pdf->Output("invoices/".$file,"F");
// Fin de generar pdf
}
/********************************************************************************************************/
/* ENVIAR E-MAIL AL USUARIO */
/********************************************************************************************************/
$link = conectar();
$sql = "SELECT * FROM members WHERE cod='".$cod_max."';";
//echo $sql;
$result_tmp = $link->query($sql);
$fila = $result_tmp->fetch_assoc();
//ENVIAR E-MAIL
$cod_language = $language;
$language = obtener('language','cod',$cod_language,'language');
//Buscamos la plantilla que le corresponda
$sql = "SELECT message, subject FROM messages WHERE type='welcome' AND language='".$language."'";
$r_tmp = $link->query($sql);
if($r_tmp->num_rows>0){
$f_tmp = $r_tmp->fetch_assoc();
$message = $f_tmp['message'];
$subject = $f_tmp['subject'];
if(trim($message) == ''){
$default_language = obtener('language','vdefault','1','language');
$sql = "SELECT message, subject FROM messages WHERE type='welcome' AND language='".$default_language."'";
$r2_tmp = $link->query($sql);
if($r2_tmp->num_rows>0){
$f2_tmp = $r2_tmp->fetch_assoc();
$message = $f2_tmp['message'];
$subject = $f2_tmp['subject'];
if(trim($message) == ''){
//Problemas - No hay ninguna plantilla del mensaje - notificamos al administrador
$candado = false;
}else{
$candado = true;
}
}else{
//Problemas - No hay ninguna plantilla del mensaje - notificamos al administrador
$candado = false;
}
}else{
//Si hay mensaje en este punto - pasamos a completarlo
$candado = true;
}
}else{
//buscamos mensaje por defecto
$default_language = obtener('language','vdefault','1','language');
$sql = "SELECT message, subject FROM messages WHERE type='welcome' AND language='".$default_language."'";
$r2_tmp = $link->query($sql);
if($r2_tmp->num_rows>0){
$f2_tmp = $r2_tmp->fetch_assoc();
$message = $f2_tmp['message'];
$subject = $f2_tmp['subject'];
if(trim($message) == ''){
//Problemas - No hay ninguna plantilla del mensaje - notificamos al administrador
$candado = false;
}else{
$candado = true;
}
}else{
//Problemas - No hay ninguna plantilla del mensaje - notificamos al administrador
$candado = false;
}
}
$sql = "SELECT sender FROM parametros";
$result = $link->query($sql);
$row_sender = $result->fetch_assoc();
$sender = $row_sender['sender'];
if($candado){
$sql = "DESCRIBE members";
$r_campos = $link->query($sql);
while($aux = $r_campos->fetch_assoc()){
if($aux['Field']=="renewal"){
$message = str_replace("{{".$aux['Field']."}}", date("d/m/Y",strtotime($fila[$aux['Field']])), $message);
}elseif($aux['Field']=="quota"){
$message = str_replace("{{".$aux['Field']."}}", (number_format($fila[$aux['Field']],2 , "," ,".").' €'), $message);
}elseif($aux['Field']=="date_arrival"){
$message = str_replace("{{".$aux['Field']."}}", date("d/m/Y",strtotime($fila[$aux['Field']])), $message);
}elseif($aux['Field']=="language"){
$tmp_language = obtener('language','cod',$fila[$aux['Field']],'language');
$message = str_replace("{{".$aux['Field']."}}", $tmp_language, $message);
}elseif($aux['Field']=="type"){
$tmp_type = obtener('type_member','cod',$fila[$aux['Field']],'name');
$message = str_replace("{{".$aux['Field']."}}", $tmp_type, $message);
}elseif($aux['Field']=="status"){
$tmp_status = obtener('status','cod',$fila[$aux['Field']],'status');
$message = str_replace("{{".$aux['Field']."}}", $tmp_status, $message);
}elseif($aux['Field']=="country"){
$tmp_country = obtener('country','iso',$fila[$aux['Field']],'printable_name');
$message = str_replace("{{".$aux['Field']."}}", $tmp_country, $message);
}else{
$message = str_replace("{{".$aux['Field']."}}", $fila[$aux['Field']], $message);
}
}
$mail = new PHPMailer();
$mail->Host = "localhost";
//Estaría bien seleccionar un remitente para que no se pierdan los correos
$mail->From = $sender;
$mail->FromName = "Administration Chamilo members";
$mail->Subject = $subject;
$mail->AddAddress($email);
/*$sql = "SELECT responsible FROM responsible WHERE area='renewal';";
$r_resp = $link->query($sql);
while($aux = $r_resp->fetch_assoc()){
//Copia a responsables
$mail->AddBCC($aux['responsible']);
}
*/
if($send_invoice=="YES"){
$mail->AddAttachment ("invoices/".$file, $file);
}
$mail->CharSet = "UTF-8";
$body = $message;
$mail->Body = $body;
$mail->AltBody = quitar_html($message);
$mail->Send();
}else{
//Notificamos al responsable
$idioma = obtener('language','cod',$cod_language,'language');
$mail = new PHPMailer();
$mail->Host = "localhost";
//$mail->From = "";
$mail->FromName = "Administration Chamilo members";
$mail->Subject = "Problem to send welcome message e-mail";
$sql = "SELECT responsible FROM responsible WHERE area='renewal';";
$r_resp = $link->query($sql);
while($aux = $r_resp->fetch_assoc()){
//Copia a responsables
$mail->AddAddress($aux['responsible']);
}
$mail->CharSet = "UTF-8";
$body = "The template for the welcome of the ".$idioma." language is not available, and the default template is not available.<br><br>Enter the platform in \"Settings\" section and select \"Message\" tabs to edit the corresponding message.<br><br>Regards";
$mail->Body = $body;
$mail->AltBody = quitar_html($message);
$mail->Send();
}
$_SESSION['info']="Added a new member";
session_write_close();
header('Location: http://'.$_SERVER['SERVER_NAME'].'/form_member.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chamilo - New Members</title>
<meta content="Chamilo - Members Management" name="description">
<!-- We need to emulate IE7 only when we are to use excanvas -->
<!--[if IE]> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <![endif]-->
<!-- Favicons -->
<!-- Main Stylesheet -->
<link type="text/css" href="css/style4.css" rel="stylesheet">
<!-- Your Custom Stylesheet -->
<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.17.custom.css" media="screen">
<!-- jQuery with plugins -->
<script src="js/jquery-1.8.2.js" type="text/javascript"></script>
<!-- Could be loaded remotely from Google CDN : <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> -->
<script src="js/jquery.ui.core.min.js" type="text/javascript"></script>
<script src="js/jquery.ui.widget.min.js" type="text/javascript"></script>
<script src="js/jquery.ui.tabs.min.js" type="text/javascript"></script>
<!-- jQuery tooltips -->
<script src="js/jquery.tipTip.min.js" type="text/javascript"></script>
<!-- Superfish navigation -->
<script src="js/jquery.superfish.min.js" type="text/javascript"></script>
<script src="js/jquery.supersubs.min.js" type="text/javascript"></script>
<!-- jQuery form validation -->
<script src="js/jquery.validate_pack.js" type="text/javascript"></script>
<!-- jQuery popup box -->
<script src="js/jquery.nyroModal.pack.js" type="text/javascript"></script>
<!-- jQuery graph plugins -->
<!--[if IE]><script type="text/javascript" src="js/flot/excanvas.min.js"></script><![endif]-->
<script src="js/flot/jquery.flot.min.js" type="text/javascript"></script>
<!-- Internet Explorer Fixes -->
<!--[if IE]> <link rel="stylesheet" type="text/css" media="all" href="css/ie.css"/> <script src="js/html5.js"></script> <![endif]-->
<!--Upgrade MSIE5.5-7 to be compatible with MSIE8: http://ie7-js.googlecode.com/svn/version/2.1(beta3)/IE8.js -->
<!--[if lt IE 8]> <script src="js/IE8.js"></script> <![endif]-->
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#renewal").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true
});
});
</script>
<script src="js/form_member.js" type="text/javascript"></script>
<!-- Internet Explorer Fixes -->
<!--[if IE]> <link rel="stylesheet" type="text/css" media="all" href="css/ie.css"/> <script src="js/html5.js"></script> <![endif]-->
<!--Upgrade MSIE5.5-7 to be compatible with MSIE8: http://ie7-js.googlecode.com/svn/version/2.1(beta3)/IE8.js -->
<!--[if lt IE 8]> <script src="js/IE8.js"></script> <![endif]-->
<script type="text/javascript">
$(document).ready(function(){
/* setup navigation, content boxes, etc... */
Administry.setup();
});
</script>
</head>
<body>
<!-- Header -->
<header id="top">
<div class="wrapper">
<!-- Title/Logo - can use text instead of image -->
<div id="title">
<img alt="Members Management" src="images/logo.png">
<!--<span>Administry</span> demo-->
</div>
<!-- Top navigation -->
<div id="topnav">
Logged in as
<b><?php echo $_SESSION['usuario']; ?></b>
<span>|</span>
<a href="setting.php">Settings</a>
<span>|</span>
<a href="logout.php">Logout</a>
<br>
</div>
<!-- End of Top navigation -->
<!-- Main navigation -->
<?php include_once 'menu/top-menu.php'; ?>
<!-- End of Main navigation -->
<!-- Future Proyect -- Aside links
<aside>
<b>English</b>
·
<a href="#">Spanish</a>
·
<a href="#">German</a>
</aside>
-->
<!-- End of Aside links -->
</div>
</header>
<!-- End of Header -->
<!-- Page title -->
<div id="pagetitle">
<div class="wrapper">
<h1>Add new member</h1>
<!-- Quick search box -->
<form method="get" action="">
<input id="q" class="" type="text" name="q">
</form>
</div>
</div>
<!-- End of Page title -->
<!-- Page content -->
<div id="page">
<?php
if(isset($_SESSION['info']) && $_SESSION['info']!=''){
echo '<div class="box box-success closeable">'.$_SESSION['info'].'</div>';
unset($_SESSION['info']);
}
?>
<!-- Wrapper -->
<div class="wrapper">
<!-- Left column/section -->
<section class="column width6 first">
<h3>Form new member</h3>
<div class="box box-info">All fields are required</div>
<form id="memberform" action="#" method="post">
<fieldset>
<p>
<label class="required" for="name">Name:</label>
<br>
<input id="name" class="half" type="text" name="name" value="">
</p>
<p>
<label class="required" for="surname">Surname:</label>
<br>
<input id="surname" class="half" type="text" name="surname" value="">
</p>
<p>
<label class="required" for="country">Country:</label>
<br>
<select id="country" class="half" name="country">
<option value="">Select country</option>
<?php
$link = conectar();
$sql = "SELECT * FROM country";
$result = $link->query($sql);
while($row = $result->fetch_assoc()){
echo '<option value="'.$row['iso'].'">'.$row['printable_name'].'</option>';
}
$result->free();
?>
</select>
</p>
<p>
<label class="required" for="language">Language:</label>
<br>
<select id="language" class="half" name="language">
<option value="">Select language</option>
<?php
$link = conectar();
$sql = "SELECT * FROM language WHERE active='1'";
$result = $link->query($sql);
while($row = $result->fetch_assoc()){
echo '<option value="'.$row['cod'].'">'.$row['language'].'</option>';
}
$result->free();
?>
</select>
</p>
<p>
<label class="required" for="phone">Phone:</label>
<br>
<input id="phone" class="half" type="text" name="phone" value="">
<small>e.g. +34 999 666 333</small>
</p>
<p>
<label class="required" for="email">Email address:</label>
<br>
<input id="email" class="half" type="text" name="email" value="">
</p>
<p>
<label class="required" for="renewal">Renewal Date: (dd/mm/yyyy)</label>
<br>
<input id="renewal" type="text" name="renewal" value="" placeholder="dd/mm/yyyy">
</p>
<p>
<label class="required" for="quota">Quota:</label>
<br>
<input id="quota" class="small" type="text" name="quota" value="" >
</p>
<p>
<label for="send_invoice">Send invoice: </label>
<input id="send_invoice" class="small" type="checkbox" name="send_invoice" value="YES" checked="checked" >
</p>
<p>
<label class="required" for="type">Type of member:</label>
<br>
<select id="type" class="half" name="type">
<option value="">Select type of member</option>
<?php
$link = conectar();
$sql = "SELECT * FROM type_member";
$result = $link->query($sql);
while($row = $result->fetch_assoc()){
echo '<option value="'.$row['cod'].'">'.$row['name'].'</option>';
}
$result->free();
?>
</select>
</p>
<div id="company" style="display:none">
<p>
<label class="required" for="institution">Institution or company:</label>
<br>
<input id="institution" class="half" type="text" name="institution" disabled="disabled" value="">
</p>
<p>
<label for="address">Address:</label>
<br>
<input id="address" class="half" type="text" name="address" value="">
</p>
<p>
<label for="postal_code">Postal Code:</label>
<br>
<input id="postal_code" class="half" type="text" name="postal_code" value="">
</p>
<p>
<label for="vat">Vat or ID number:</label>
<br>
<input id="vat" class="half" type="text" name="vat" value="">
</p>
</div>
<p>
<label class="required" for="status">Status:</label>
<br>
<select id="status" class="half" name="status">
<option value="">Select status</option>
<?php
$link = conectar();
$sql = "SELECT * FROM status";
$result = $link->query($sql);
while($row = $result->fetch_assoc()){
echo '<option value="'.$row['cod'].'">'.$row['status'].'</option>';
}
$result->free();
?>
</select>
</p>
<p>
<label for="area2">Comment:</label>
<br>
<textarea id="comment" class="medium full" name="comment"></textarea>
</p>
<p class="box">
<input class="btn btn-green big" type="submit" name="sendform" value="Validate">
or
<input class="btn" type="reset" value="Reset">
</p>
</fieldset>
</form>
</section>
<!-- End of Left column/section -->
<!-- Right column/section -->
<?php include_once 'menu/right-menu.php'; ?>
<!-- End of Right column/section -->
</div>
<!-- End of Wrapper -->
</div>
<!-- End of Page content -->
<!-- Page footer -->
<?php include_once 'menu/footer-menu.php'; ?>
<!-- End of Animated footer -->
<!-- Scroll to top link -->
<a id="totop" style="display: block;">^ scroll to top</a>
<!-- Admin template javascript load -->
<script src="js/administry.js" type="text/javascript"></script>
<div id="tiptip_holder" style="max-width:200px;">
<div id="tiptip_arrow">
<div id="tiptip_arrow_inner"></div>
</div>
<div id="tiptip_content"></div>
</div>
</body>
</html>