-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimportCursos.php
executable file
·138 lines (121 loc) · 2.38 KB
/
importCursos.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
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CATMAN - FUSM</title>
</head>
<BODY>
<?php
define('APP_PATH', dirname(__FILE__) );
define( 'DS', '/' );
include ('includes/elfic.ini.php');
function getCatedraId($catedra)
{
$db = new DB();
$sql = "SELECT id FROM catedra WHERE nombre = '$catedra'";
return $db->queryUniqueValue($sql);
}
function getTutorId($tutor)
{
$t = array();
$t = explode(' ', $tutor);
$apellido = $t[0];
$nombre = isset($t[1]) ? $t[1] : 0;
$db = new DB();
$sql = "SELECT id FROM usuarios "
. "WHERE nombres LIKE '%$nombre%' AND apellidos LIKE '%$apellido%'";
return $db->queryUniqueValue($sql);
}
function getDia($fecha)
{
if($fecha == "") return "";//Mar. 6:30 - 10:00 pm
$t = explode(' ', $fecha);
$dia = $t[0];
switch($dia)
{
case 'Lun.': return 1;
break;
case 'Mar.': return 2;
break;
case 'Mie.': return 3;
break;
case 'Jue.': return 4;
break;
case 'Vie.': return 5;
break;
case 'Sab.': return 6;
break;
case 'Dom.': return 7;
}
}
function sumaTiempo($horas)
{
$t = explode(":", $horas);
return $t[0] + 12 .":".$t[1];
}
function getHora($fecha)
{
//Mar. 6:30 - 10:00 pm
if($fecha == "") return "";
$h = explode(' ', $fecha);
$hm = $h[1];
if(isset($h[4]) && $h[4] == "pm")
{
return sumaTiempo($hm);
}
else
{
return $hm;
}
}
$row = 1;
$f = fopen ("cursos.csv","r");
$i = 1;
$j = 1;
while ($data = fgetcsv ($f, 1000, ";"))
{
$cid = getCatedraId(isset($data[0]) ? $data[0]: 0);
$tid = getTutorId(isset($data[2]) ? $data[2] : 0);
if($cid > 0 && $tid > 0)
{
$p['catedra_id'] = $cid;
$p['grupo'] = isset($data[1]) ? $data[1] : "" ;
$p['tutor_id'] = $tid;
$p['periodo_id'] = 2;
$p['dia'] = getDia(isset($data[3]) ? $data[3] : "");
$p['hora'] = getHora(isset($data[3]) ? $data[3] : "");
$p['estado'] = 1;
$db = new DB();
if(!$db->perform('cursos', $p))
{
//echo "Error creando curso " .$data[0];
//echo "\n<br>";
}
else
{
//echo "Se creó el curso " . $data[0];
//echo "\n<br>";
$i++;
}
}
else
{
echo "$j - <span style='color: red;'>";
if(!$cid)
{
echo "No se recupero id de catedra $data[0]";
echo "\n<br>";
}
if(!$tid)
{
echo "No se recupero tutor $data[2]";
echo "\n<br>";
}
echo "</span>";
$j++;
}
}
fclose ($f);
echo "TOTAL IMPORTADOS: $i";
?>
</BODY>
</html>