-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateCourse.php
130 lines (64 loc) · 2.32 KB
/
generateCourse.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
<?php
/*Importing TI-Var Lib*/
include_once "libAdriweb\src/autoloader.php";
include_once "libAdriweb\src/TypeHandlers/TH_0x05.php";
use tivars\TIModel;
use tivars\TIVarFile;
use tivars\TIVarType;
use tivars\TIVarTypes;
session_start();
/*Define some constants */
define("MIN_PAS_Y", 12);
define("MIN_PAS_X", 0);
define("MAX_CHAR_LINE", 33);
define("LAST_LINE", 13);
if(isset($_POST['course_input']) AND !empty($_POST['course_input'])){
$course = htmlspecialchars(trim($_POST['course_input']));
$size = strlen($course);
$Cptlines = 0;
$CptlinesSave = 0;
$CptPages = 1;
$YText = 0;
$XText = 0;
$stopTransfFlag = 0;
$extCpt = 0;
$outputString = '0→Xmin:0→Ymin:1→∆X:1→∆Y:AxesOff:BackgroundOff:ClrDraw:';
for ($i=1; $i<=$size ; $i++) {
if($stopTransfFlag == 0){
$extCpt++;
}
if(substr($course,$i-1,1) == '$' AND $stopTransfFlag == 0){
$stopTransfFlag = 1; //on arrete le traitement
}elseif (substr($course,$i-1,1) == '$' AND $stopTransfFlag == 1) {
$stopTransfFlag = 0; //on reprend le traitement
}
echo $stopTransfFlag;
if($extCpt % MAX_CHAR_LINE == 0){
$outputString.='Text('.$YText.','.$XText.',"'.substr($course, $CptlinesSave*MAX_CHAR_LINE, MAX_CHAR_LINE).'"):';
$Cptlines++;
$CptlinesSave++;
$YText+=MIN_PAS_Y;
}
if($Cptlines == LAST_LINE){
$outputString.='Pause :ClrDraw:';
$YText = 0;
$Cptlines = 0;
$CptPages++;
}
}
$outputString.='Pause :ClrDraw:Disp " ';
echo '<textarea rows="20" cols="100">'.$outputString.'</textarea>';
/*Generate 8xp File*/
$id_course = uniqid();
$name = "COURS";
$newPrgm = TIVarFile::createNew(TIVarType::createFromName("Program"), $name, TIModel::createFromName("84+"));
$newPrgm->setContentFromString($outputString);
$newPrgm->saveVarToFile("generatedCourses", $id_course);
/*Go back and give download link*/
$_SESSION['error_course'] = '<br /><span style="color:green;">Votre fichier est disponible ici: <a href="generatedCourses/'.$id_course.'.8xp">Télécharger</a></span>';
//header('location: createCourse.php?mode=OK');
}else{
$_SESSION['error_course'] = '<span style="color:red;">Vous devez saisir un texte!</span>';
header('location: createCourse.php');
}
?>