Skip to content
Snippets Groups Projects
Commit 817f613c authored by Victoria's avatar Victoria
Browse files

Support of xml import

parent 8077308e
Branches
Tags
No related merge requests found
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_XMLCreator extends Controller_Handler
{
// Таблица баллов (со страницы оценивания) [dev version]
public function action_GenerateXMLFile() {
$disciplineID = $this->post['disciplineID'];
$groupID = $this->post['studyGroupID'];
// make form from template
$info = Model_Rating::getFinalFormInfo($disciplineID, $groupID)[0];
$info['DisciplineID'] = $disciplineID;
// prepare filename
$grade = $info["GradeNum"];
$group = $info["GroupNum"];
$faculty = $info['FacultyName'];
$subjName = $info["SubjectName"];
$type = $info['ExamType'];
$stage = 1; // TODO: user should provide stage
$rates = Model_Rating::getRatesForStudentsGroupByStage($disciplineID, $groupID, $stage);
$examHold = 1;
// if ($type === 'exam')
// $examHold = $this->checkExamIsHold($rates);
$filename = $type."_".$grade."_".$group;
$fp = fopen ("test.xml", "w+");
$degree = $info['Degree'];
if ($degree=="bachelor")
$degree="Бакалавр";
else if ($degree=="master")
$degree="Магистр";
else
$degree="Специалист";
if ($type=="exam")
$type="Экзамен";
else if ($type=="credit")
$type="Зачет";
else
$type="Дифференцированный зачет";
$gradeNum = $info['GradeNum'];
fputs($fp,"<?xml version='1.0' encoding='UTF-8'?>\n");
fputs($fp,"<document\n>");
fputs($fp,"<header\n>");
$semester = $info['SemesterNum'];
fputs($fp,"<semester>\n".$semester."</semester>\n");
fputs($fp,"<faculty>\n".$faculty."</faculty>\n");
fputs($fp,"<grade>\n".$gradeNum."</grade>\n");
fputs($fp,"<degree>\n".$degree."</degree>\n");
fputs($fp,"<spec>\n".$info['SpecName']." ".$info['SpecCode']."</spec>\n");
fputs($fp,"<group>\n".$group."</group>\n");
fputs($fp,"<subjName>\n".$subjName."</subjName>\n");
fputs($fp,"<examtype>\n".$type."</examtype>\n");
$countteachers = Model_Teachers::getNamesForDiscipline($info['DisciplineID'],true,true);
$teachers = Model_Teachers::ofDiscipline($info['DisciplineID']);
$teachersStr = '';
fputs($fp,"<teachers>\n");
if (count($countteachers)>1){
foreach ($teachers as $row) {
fputs($fp,"<teacher>\n");
fputs($fp,"<lastName>\n".$row['LastName']."</lastName>\n");
fputs($fp,"<firstName>\n".$row['FirstName']."</firstName>\n");
fputs($fp,"<secondName>\n".$row['SecondName']."</secondName>\n");
fputs($fp,"</teacher>\n");
}
/*for($i=0;$i<count($teachers);++$i)
{
fputs($fp,$teachers[$i].' ');
}*/
}
else
{
fputs($fp,"<teacher>\n");
fputs($fp,"<lastName>\n".$info['LastName']."</lastName>\n");
fputs($fp,"<firstName>\n".$info['FirstName']."</firstName>\n");
fputs($fp,"<secondName>\n".$info['SecondName']."</secondName>\n");
fputs($fp,"</teacher>\n");
}
fputs($fp,"</teachers>\n");
fputs($fp,"</header\n>");
fputs($fp,"<rates\n>");
foreach($rates as $studentRates) {
fputs($fp,"<student\n>");
$lastName = $studentRates['LastName'];
$firstName = $studentRates['FirstName'];
$secondName = $studentRates['SecondName'];
$fullName = $lastName." ".$firstName." ".$secondName;
fputs($fp,"<lastName>\n".$lastName."</lastName>\n");
fputs($fp,"<firstName>\n".$firstName."</firstName>\n");
fputs($fp,"<secondName>\n".$secondName."</secondName>\n");
$ratesSet['semester'] = (int)$studentRates['regular'];
$ratesSet['bonus'] = (int)$studentRates['bonus'];
$ratesSet['extra'] = (int)$studentRates['extra'];
$ratesSet['exam'] = (int)$studentRates['exam'];
$totalRate = $ratesSet['bonus'] + $ratesSet['exam']+$ratesSet['semester'] + $ratesSet['extra'];
fputs($fp,"<totalRate>\n".$totalRate."</totalRate>\n");
//fputs($fp,"<semesterRate>\n".$ratesSet['semester']."</semesterRate>\n");
// fputs($fp,"<bonusRate>\n".$ratesSet['bonus']."</bonusRate>\n");
fputs($fp,"</student\n>");
}
fputs($fp,"</rates\n>");
fputs($fp,"</document\n>");
fclose($fp);
$options = [
'mime_type' => File::mime_by_ext('xml'),
'delete'=>true
];
//$filename=self::encodestring($filename);
$this->response->send_file('test.xml', $filename.'.xml', $options);
}
}
\ No newline at end of file
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
<button class="defaultForm BlueButton HalfWidth" id="DownloadExamDocument" disabled="disabled">Скачать</button> <button class="defaultForm BlueButton HalfWidth" id="DownloadExamDocument" disabled="disabled">Скачать</button>
<button class="defaultForm BlueButton HalfWidth" id="BlockExamDiscipline" disabled="disabled">Блокировать</button> <button class="defaultForm BlueButton HalfWidth" id="BlockExamDiscipline" disabled="disabled">Блокировать</button>
<button class="defaultForm BlueButton HalfWidth" id="BlockAndPrintExam" disabled="disabled">Блокировать и Скачать</button> <button class="defaultForm BlueButton HalfWidth" id="BlockAndPrintExam" disabled="disabled">Блокировать и Скачать</button>
<button class="defaultForm BlueButton HalfWidth" id="DownloadXML" disabled="disabled">Скачать в формате XML</button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -21,6 +21,7 @@ $(function() { ...@@ -21,6 +21,7 @@ $(function() {
var jDownloadExamDocument = $("#DownloadExamDocument"); var jDownloadExamDocument = $("#DownloadExamDocument");
var jSelectGroup = $("#SelectGroup"); var jSelectGroup = $("#SelectGroup");
var jSelectDiscipline = $("#SelectDiscipline"); var jSelectDiscipline = $("#SelectDiscipline");
var jDownloadXML = $("#DownloadXML");
$("#ExamChoice").change(controlVisualization); $("#ExamChoice").change(controlVisualization);
$("#CreditChoice").change(controlVisualization); $("#CreditChoice").change(controlVisualization);
...@@ -61,6 +62,7 @@ $(function() { ...@@ -61,6 +62,7 @@ $(function() {
jDownloadStatement.attr("disabled", "disabled"); jDownloadStatement.attr("disabled", "disabled");
} }
jDownloadExamDocument.attr("disabled", "disabled"); jDownloadExamDocument.attr("disabled", "disabled");
jDownloadXML.attr("disabled", "disabled");
}); });
$("#SelectGroup").change(function() { $("#SelectGroup").change(function() {
...@@ -94,14 +96,20 @@ $(function() { ...@@ -94,14 +96,20 @@ $(function() {
} }
else jDownloadStatement.attr("disabled", "disabled"); else jDownloadStatement.attr("disabled", "disabled");
jDownloadXML.attr("disabled", "disabled");
jDownloadExamDocument.attr("disabled", "disabled"); jDownloadExamDocument.attr("disabled", "disabled");
}); });
$("#SelectDiscipline").change(function() { $("#SelectDiscipline").change(function() {
var disciplineID = parseInt($(this).val()) || 0; var disciplineID = parseInt($(this).val()) || 0;
if (disciplineID > 0) if (disciplineID > 0){
jDownloadExamDocument.removeAttr("disabled"); jDownloadExamDocument.removeAttr("disabled");
else jDownloadExamDocument.attr("disabled", "disabled"); jDownloadXML.removeAttr("disabled");
}
else {
jDownloadExamDocument.attr("disabled", "disabled");
jDownloadXML.attr("disabled", "disabled");
}
}); });
// Скачать ведомость // Скачать ведомость
...@@ -140,6 +148,24 @@ $(function() { ...@@ -140,6 +148,24 @@ $(function() {
}); });
}); });
$('body').on('click', '#DownloadXML', function(){
$.fileDownload(g_URLdir + 'handler/XMLCreator/GenerateXMLFile', {
httpMethod: "POST",
data:
{
"disciplineID": parseInt($("#SelectDiscipline").val()),
"studyGroupID": parseInt($("#SelectGroup").val())
},
successCallback: function () {
},
failCallback: function () {
}
});
});
// Блокирование дисциплины // Блокирование дисциплины
// Печать ведомости и блокирование дисциплины // Печать ведомости и блокирование дисциплины
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment