-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·557 lines (478 loc) · 19 KB
/
index.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
<?php
/*##############################################################################
# Project: Labels - Extremadura High Schools
# Purpose: Module to generate labels of students for laptops
# Date: 24-Sep-2010.
# Ver.: 29-Sep-2010.
# Copyright: 2010 - Manu Mora Gordillo <manuito @nospam@ gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################################## */
if($_POST["action"]=="generate_labels"){
require('fpdf/fpdf.php');
include('qr/qr_img.php');
// Conectamos con LDAP
$user="cn=".$_POST["userLDAP"].",ou=People,dc=instituto,dc=extremadura,dc=es";
$conex=ldap_connect("ldap://".$_POST["hostLDAP"], 389) or die ("No ha sido posible conectarse al servidor<br><br><input type='button' value='Volver' onClick='location.href=\"index.php\"'/>");
if (!@ldap_set_option($conex, LDAP_OPT_PROTOCOL_VERSION, 3))
die("Falló la configuracion de protocolo version 3<br><br><input type='button' value='Volver' onClick='location.href=\"index.php\"'/>");
if (!@ldap_bind($conex, $user, $_POST["password"]))
die("Upsss, falló la autenticación. Vuelve a intentarlo otra vez.<br><br><input type='button' value='Volver' onClick='location.href=\"index.php\"'/>");
// Obtenemos la info de LDAP
$dn = "ou=Group,dc=instituto,dc=extremadura,dc=es";
$filter="(|";
for($i=0;$i<count($_POST["classroomGroup"]);$i++){
$filter.="(cn=".$_POST["classroomGroup"][$i].")";
}
$filter.=")";
$fields = array("cn","grouptype","memberuid");
$sr=ldap_search($conex, $dn, $filter,$fields);
$groups = ldap_get_entries($conex, $sr);
$students = array();
for($i=0;$i<count($groups);$i++){
if($groups[$i]["grouptype"][0]=="school_class"){
for($j=0;$j<count($groups[$i]["memberuid"]);$j++){
if($groups[$i]["memberuid"][$j]!="")
$students[] = $groups[$i]["memberuid"][$j];
}
}
}
if(count($students)=="0")
die("No se han encontrado alumnos.<br><br><input type='button' value='Volver' onClick='location.href=\"index.php\"'/>");
sort($students);
$filter = "uid=*";
if($_POST["filter"]!=""){
// para que imprima la etiqueta en una posicion determinada de la pagina de etiquetas
//$offset = $_POST["offset"];
//$num_label = $offset - 1;
$array_filter = explode(",",$_POST["filter"]);
$filter = "(|";
for($r=0;$r<count($array_filter);$r++){
$filter.="(uid=*".trim($array_filter[$r])."*)";
}
$filter.= ")";
//$filter = $_POST["filter"]."*";
}
//echo ">>>>>>".$filter;
$dn = "ou=People,dc=instituto,dc=extremadura,dc=es";
$fields = array("uid","cn","employeenumber","jpegphoto");
$sr=ldap_search($conex, $dn, $filter, $fields);
//$sr=ldap_search($conex, $dn, "(|(uid=*marriaza*)(uid=*arodriguez*))", $fields);
$students_tmp = ldap_get_entries($conex, $sr);
// Llenar labels con posiciones vacias, para poner offset en etiquetas y comenzar a imprimir en una det. posicion
$offset = $_POST["offset"];
for ($j=1;$j<$offset;$j++)
$labels[] = array("cn"=>"","uid"=>"","nie"=>"","foto"=>"");
for($i=0;$i<count($students_tmp);$i++){
if(in_array($students_tmp[$i]["uid"][0],$students))
$labels[] = array("cn"=>$students_tmp[$i]["cn"][0],"uid"=>$students_tmp[$i]["uid"][0],"nie"=>$students_tmp[$i]["employeenumber"][0],"foto"=>$students_tmp[$i]["jpegphoto"][0]);
//echo ">>>>>>>>>>>>>>>>".$students_tmp[$i]["jpegphoto"][0];
}
// Creamos el PDF
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',8);
$num_rows = $_POST["rows"];
$num_cols = $_POST["columns"];
$margenX = $_POST["xMargin"];
$margenY = $_POST["yMargin"];
$ancho = $_POST["width"];
$alto = $_POST["height"];
$QR_size=$_POST["qrSize"];
$photoWidth=$_POST["photoWidth"];
$photoHeight=$_POST["photoHeight"];
$num_label=0;
if(!file_exists("tmp")){
mkdir("tmp");
}
for($i=0;$i<$num_rows;$i++){
for($j=0;$j<$num_cols;$j++){
if(($num_label)==count($labels)){
$pdf->Output();
exit();
}
$x = $margenX + $j*$alto;
$y = $margenY + $i*$ancho;
// Para control de la posicion de inicio de impresion de las etiquetas
if ($labels[$num_label]["cn"] != "") {
$pdf->Text($x, $y+$QR_size+2, $labels[$num_label]["cn"]);
if(isset($_POST["org"]))
$pdf->Text($x, $y+$QR_size+5, $_POST["org"]." - ".$labels[$num_label]["uid"]);
else
$pdf->Text($x, $y+$QR_size+5, $labels[$num_label]["uid"]);
$micro = explode(" ",microtime());
$id = time().$micro[0];
$student_data = 'BEGIN:VCARD'.urldecode("%0A");
$student_data.= 'N:'.$labels[$num_label]["cn"].urldecode("%0A");
$student_data.= 'ROLE:Student'.urldecode("%0A");
if(isset($labels[$num_label]["nie"]))
$student_data.= 'UID:'.$labels[$num_label]["nie"].urldecode("%0A");
if(isset($_POST["org"]))
$student_data.= 'ORG:'.$_POST["org"].urldecode("%0A");
if(isset($_POST["address"]))
$student_data.= 'ADR:'.$_POST["address"].urldecode("%0A");
if(isset($_POST["phone"]))
$student_data.= 'TEL:'.$_POST["phone"].urldecode("%0A");
if(isset($_POST["email"]))
$student_data.= 'EMAIL:'.$_POST["email"].urldecode("%0A");
if(isset($_POST["web"]))
$student_data.= 'URL:'.$_POST["web"].urldecode("%0A");
$student_data.= 'END:VCARD';
generateQRCode($student_data,"tmp/QR".$id.".png");
if(file_exists("tmp/QR".$id.".png")){
$pdf->Image("tmp/QR".$id.".png",$x,$y,$QR_size);
@unlink("tmp/QR".$id.".png");
}
if($labels[$num_label]["foto"]!=""){
$photoStudent = "tmp/Alu".$id.".png";
$im = @imagepng(@imagecreatefromstring($labels[$num_label]["foto"]),$photoStudent);
if ($im !== false && file_exists($photoStudent))
$pdf->Image($photoStudent, $x + $QR_size, $y, $photoWidth, $photoHeight);
@unlink($photoStudent);
}
}
$num_label++;
if(($i+1)==$num_rows && ($j+1)==$num_cols && ($num_label+1)<count($labels)){
$pdf->AddPage();
$i=0;
$j=-1;
}
}
}
$pdf->Output();
exit();
} elseif($_POST["action"]=="generate_spreadsheet"){
require_once('ods/ods.php');
// Conectamos con LDAP
$user="cn=".$_POST["userLDAP"].",ou=People,dc=instituto,dc=extremadura,dc=es";
$conex=ldap_connect("ldap://".$_POST["hostLDAP"], 389) or die ("No ha sido posible conectarse al servidor<br><br><input type='button' value='Volver' onClick='location.href=\"index.php\"'/>");
if (!@ldap_set_option($conex, LDAP_OPT_PROTOCOL_VERSION, 3))
die("Falló la configuracion de protocolo version 3<br><br><input type='button' value='Volver' onClick='location.href=\"index.php\"'/>");
if (!@ldap_bind($conex, $user, $_POST["password"]))
die("Upsss, falló la autenticación. Vuelve a intentarlo otra vez.<br><br><input type='button' value='Volver' onClick='location.href=\"index.php\"'/>");
// Obtenemos la info de LDAP
$dn = "ou=Group,dc=instituto,dc=extremadura,dc=es";
$filter="(|";
for($i=0;$i<count($_POST["classroomGroup"]);$i++){
$filter.="(cn=".$_POST["classroomGroup"][$i].")";
}
$filter.=")";
$fields = array("cn","grouptype","memberuid");
$sr=ldap_search($conex, $dn, $filter,$fields);
$groups = ldap_get_entries($conex, $sr);
for($i=0;$i<count($groups);$i++){
if($groups[$i]["grouptype"][0]=="school_class"){
for($j=0;$j<count($groups[$i]["memberuid"]);$j++){
if($groups[$i]["memberuid"][$j]!=""){
$listGroups[$groups[$i]["cn"][0]][] = $groups[$i]["memberuid"][$j];
}
}
}
}
ksort($listGroups);
$filter = "";
if($_POST["filter"]!="")
$filter = $_POST["filter"]."*";
$dn = "ou=People,dc=instituto,dc=extremadura,dc=es";
$fields = array("uid","cn","employeenumber");
$sr=ldap_search($conex, $dn, "uid=*".$filter, $fields);
$students_tmp = ldap_get_entries($conex, $sr);
$completeListGroups = array();
foreach($listGroups as $key=>$value){
sort($value);
$students = array();
for($i=0;$i<count($students_tmp);$i++){
if(in_array($students_tmp[$i]["uid"][0],$value))
$students[$students_tmp[$i]["uid"][0]] = array("class"=>$key,"cn"=>$students_tmp[$i]["cn"][0],"uid"=>$students_tmp[$i]["uid"][0],"nie"=>$students_tmp[$i]["employeenumber"][0]);
}
ksort($students);
$completeListGroups[$key] = $students;
}
$ods = new ods();
$ods->setPath2OdsFiles('ods');
$table = new odsTable('table 1');
foreach($completeListGroups as $key=>$group)
foreach($group as $key2=>$list){
$row = new odsTableRow();
$row->addCell( new odsTableCellString($list["class"]) );
$row->addCell( new odsTableCellString($list["cn"]) );
$row->addCell( new odsTableCellString($list["uid"]) );
$table->addRow($row);
}
$ods->addTable($table);
$ods->downloadOdsFile("ListadoAlumnos.ods");
}
?>
<html>
<head>
<title>Generador de etiquetas - Centros Educativos de Extremadura</title>
<link rel="stylesheet" type="text/css" media="screen" href="style.css" />
<script type="text/JavaScript" language="javascript" src="jquery/jquery-1.4.2.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="jquery/ui/css/ui-lightness/jquery-ui-1.8.5.custom.css" />
<script type="text/JavaScript" language="javascript" src="jquery/ui/jquery-ui-1.8.5.custom.min.js"></script>
<script languaje="javascript">
function cargaSelectOffset () {
var select = document.getElementById("offset");
for (i=1;i<=23;i++)
select.options[select.length] = new Option(i, i);
}
$(function() {
$("#sliderHeight").slider({
value:70,
min: 30,
max: 150,
step: 1,
slide: function(event, ui) {
$("#height").val(ui.value);
}
});
$("#height").val($("#sliderHeight").slider("value"));
$("#sliderWidth").slider({
value:37,
min: 10,
max: 100,
step: 1,
slide: function(event, ui) {
$("#width").val(ui.value);
}
});
$("#width").val($("#sliderWidth").slider("value"));
$("#sliderRows").slider({
value:8,
min: 1,
max: 20,
step: 1,
slide: function(event, ui) {
$("#rows").val(ui.value);
}
});
$("#rows").val($("#sliderRows").slider("value"));
$("#sliderColumns").slider({
value:3,
min: 1,
max: 10,
step: 1,
slide: function(event, ui) {
$("#columns").val(ui.value);
}
});
$("#columns").val($("#sliderColumns").slider("value"));
$("#sliderxMargin").slider({
value:5,
min: 1,
max: 40,
step: 1,
slide: function(event, ui) {
$("#xMargin").val(ui.value);
}
});
$("#xMargin").val($("#sliderxMargin").slider("value"));
$("#slideryMargin").slider({
value:2,
min: 1,
max: 40,
step: 1,
slide: function(event, ui) {
$("#yMargin").val(ui.value);
}
});
$("#yMargin").val($("#slideryMargin").slider("value"));
$("#sliderphotoWidth").slider({
value:21,
min: 10,
max: 40,
step: 1,
slide: function(event, ui) {
$("#photoWidth").val(ui.value);
}
});
$("#photoWidth").val($("#sliderphotoWidth").slider("value"));
$("#sliderphotoHeight").slider({
value:25,
min: 10,
max: 40,
step: 1,
slide: function(event, ui) {
$("#photoHeight").val(ui.value);
}
});
$("#photoHeight").val($("#sliderphotoHeight").slider("value"));
$("#sliderqrSize").slider({
value:27,
min: 10,
max: 40,
step: 1,
slide: function(event, ui) {
$("#qrSize").val(ui.value);
}
});
$("#qrSize").val($("#sliderqrSize").slider("value"));
$( "buttonLabels, input:submit, a", "#buttonLabels" ).button();
$( "buttonGroups, input:button, a", "#buttonGroups" ).button();
$(".ui-state-error").hide();
$("#buttonLabels").hide();
})
function error(msn){
$("#messageGetGroups").html(msn);
$(".ui-state-error").show("slide",{},500);
}
function getGroups(){
$.getJSON("backend.php?hostLDAP="+$("#hostLDAP").val()+"&userLDAP="+$("#userLDAP").val()+"&password="+$("#password").val(),
function(data){
switch(data.msg){
case 'noConnect':{ error("No se pudo conectar con el Host"); break; }
case 'noProtocol':{ error("Falló la configuracion de protocolo"); break; }
case 'noPassword':{ error("Password incorrecto"); break; }
case 'noGroups':{ error("No se han encontrado grupos"); break; }
default:{
$(".ui-state-error").hide();
$("#buttonLabels").show();
$("#buttonGroups").empty();
$("#buttonGroups").append("Grupos<br><select multiple size='10' name='classroomGroup[]' id='classroomGroup'></select>");
$.each(data.groups, function(i,item){
$("#classroomGroup").append("<option value='"+item+"'>"+item+"</option>");
});
}
}
});
}
</script>
</head>
<body onload="cargaSelectOffset()">
<h1 style="text-align:center;">Generador de etiquetas - Centros Educativos de Extremadura</h1>
<form id='form_labels' method='POST' action="index.php">
<table style="width:100%;">
<tr>
<td colspan="2" style="width:25%; vertical-align:top;">
<fieldset><legend>LDAP</legend>
<div style="padding-left:10px">
<p>Servidor LDAP:<br>
<input type='text' id='hostLDAP' name='hostLDAP' class="text ui-widget-content ui-corner-all" value=''>
</p>
<p>Usuario:<br>
<input type='text' id='userLDAP' name='userLDAP' class="text ui-widget-content ui-corner-all" value='admin'>
</p>
<p>Contraseña:<br>
<input type='password' id='password' name='password' class="text ui-widget-content ui-corner-all">
</p>
<div id="buttonGroups"><input type="button" value="Obtener grupos" onClick="getGroups();"></div>
<br>
<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
<strong id="messageGetGroups"></strong></p>
</div>
</div>
</fieldset>
</td>
<td style="width:42%; vertical-align:top;">
<fieldset><legend>Parámetros etiquetas</legend>
<div style="padding-left:10px">
<p>
<label for="height">Ancho Etiqueta:</label>
<input type="text" id="height" name="height" style="border:0; color:#f6931f; font-weight:bold; width:30px; text-align:center;" />
<div id="sliderHeight" style="width:300px;"></div>
</p>
<p>
<label for="width">Alto Etiqueta:</label>
<input type="text" id="width" name="width" style="border:0; color:#f6931f; font-weight:bold; width:30px; text-align:center;" />
<div id="sliderWidth" style="width:300px;"></div>
</p>
<p>
<label for="rows">Filas:</label>
<input type="text" id="rows" name="rows" style="border:0; color:#f6931f; font-weight:bold; width:30px; text-align:center;" />
<div id="sliderRows" style="width:300px;"></div>
</p>
<p>
<label for="columns">Columnas:</label>
<input type="text" id="columns" name="columns" style="border:0; color:#f6931f; font-weight:bold; width:30px; text-align:center;" />
<div id="sliderColumns" style="width:300px;"></div>
</p>
<p>
<label for="xMargin">Margen X:</label>
<input type="text" id="xMargin" name="xMargin" style="border:0; color:#f6931f; font-weight:bold; width:30px; text-align:center;" />
<div id="sliderxMargin" style="width:300px;"></div>
</p>
<p>
<label for="yMargin">Margen Y:</label>
<input type="text" id="yMargin" name="yMargin" style="border:0; color:#f6931f; font-weight:bold; width:30px; text-align:center;" />
<div id="slideryMargin" style="width:300px;"></div>
</p>
<p>
<label for="photoSize">Tamaño Foto (Ancho):</label>
<input type="text" id="photoWidth" name="photoWidth" style="border:0; color:#f6931f; font-weight:bold; width:30px; text-align:center;" />
<div id="sliderphotoWidth" style="width:300px;"></div>
</p>
<p>
<label for="photoSize">Tamaño Foto (Alto):</label>
<input type="text" id="photoHeight" name="photoHeight" style="border:0; color:#f6931f; font-weight:bold; width:30px; text-align:center;" />
<div id="sliderphotoHeight" style="width:300px;"></div>
</p>
<p>
<label for="qrSize">Tamaño QR-Code:</label>
<input type="text" id="qrSize" name="qrSize" style="border:0; color:#f6931f; font-weight:bold; width:30px; text-align:center;" />
<div id="sliderqrSize" style="width:300px;"></div>
</p>
<p>
<label for="filter">Filtro:</label><br>
<input type="text" id="filter" name="filter" class="text ui-widget-content ui-corner-all"/> Valores separados por comas <b>(p.e. jprado, agordillo)</b>
</p>
<p>
<label for="offset">Empezar en la posición</label><br>
<select id="offset" name="offset">
</select>
</p>
<p style="text-align:center; font-weight:bold;">Parámetros por defecto para etiquetas apli24</p>
</div>
</fieldset>
</td>
<td style="width:33%; vertical-align:top;">
<fieldset><legend>Datos QR-Code (opcional) <a href="http://es.wikipedia.org/wiki/C%C3%B3digo_QR" target="_blank">Info Wikipedia</a></legend>
<div style="padding-left:10px">
<p>Organización:<br>
<input type="text" id="org" name="org" class="text ui-widget-content ui-corner-all"/> (p.e. IES Sta Eulalia)
</p>
<p>Dirección<br>
<input type="text" id="address" name="address" class="text ui-widget-content ui-corner-all"/>
</p>
<p>Teléfono<br>
<input type="text" id="phone" name="phone" class="text ui-widget-content ui-corner-all"/>
</p>
<p>Email<br>
<input type="text" id="email" name="email" class="text ui-widget-content ui-corner-all"/>
</p>
<p>Web<br>
http://<input type="text" id="web" name="web" class="text ui-widget-content ui-corner-all"/>
</p>
<p style="text-align:center; font-weight:bold;">Se incluirá además el Nombre, Apellidos y NIE del alumno.</p>
</div>
</fieldset>
</td>
</tr>
<tr>
<td colspan="4" style="text-align:center;"><p>Tipo
<select id="action" name="action">
<option value="generate_labels">Etiquetas</option>
<option value="generate_spreadsheet">Hoja de Cálculo</option>
</select>
</p>
</td>
</tr>
<tr>
<td colspan="4" style="text-align:center;"><br><div id="buttonLabels"><input type="submit" value="Generar"></div></td>
</tr>
</table>
</form>
</body>
</html>