764 lines
33 KiB
PHP
764 lines
33 KiB
PHP
<?php
|
||
session_start();
|
||
|
||
if(!isset($TS)) header('Location: /');
|
||
include_once $_SERVER['DOCUMENT_ROOT'].'/inc/class_SYSTEM.php';
|
||
$SYSTEMclass = new SYSTEMclass();
|
||
|
||
$TB['grupps'] = $ST['dbpf'].'_test_grupps';
|
||
$TB['razde'] = $ST['dbpf'].'_test_razdel';
|
||
$TB['tests'] = $ST['dbpf'].'_test_tests';
|
||
$TB['quest'] = $ST['dbpf'].'_test_questions';
|
||
$TB['answe'] = $ST['dbpf'].'_test_answers';
|
||
$uploaddir = 'moodle/uploads/'.$_SESSION['user']['teacher']['id'].'/';
|
||
if(!file_exists($uploaddir)) mkdir($uploaddir);
|
||
$tmpdir = 'moodle/tmp/'.$_SESSION['user']['teacher']['id'].'/';
|
||
if(!file_exists($tmpdir)) mkdir($tmpdir);
|
||
|
||
{//DATABASEs-TABLES
|
||
$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['tests'].'` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`data_c` int(11) NOT NULL,
|
||
`id_user` int(11) NOT NULL,
|
||
`id_razdel` int(11) NOT NULL,
|
||
`name` varchar(255) NOT NULL,
|
||
`descrip` TEXT NOT NULL,
|
||
`status` tinyint(4) NOT NULL,
|
||
`random_q` tinyint(4) NOT NULL,
|
||
`tests` tinyint(4) NOT NULL,
|
||
`data_testa` int(11) NOT NULL,
|
||
PRIMARY KEY (`id`)
|
||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
|
||
$rez = $DB->QUR($sql);
|
||
$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['quest'].'` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`id_tests` int(11) NOT NULL,
|
||
`text_q` TEXT NOT NULL,
|
||
`ocenka` float NOT NULL,
|
||
`tip` tinyint(4) NOT NULL,
|
||
`random_a` tinyint(4) NOT NULL,
|
||
`tests` tinyint(4) NOT NULL,
|
||
`pos` INT NOT NULL,
|
||
PRIMARY KEY (`id`)
|
||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
|
||
$rez = $DB->QUR($sql);
|
||
$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['answe'].'` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`id_questions` int(11) NOT NULL,
|
||
`text_a` TEXT NOT NULL,
|
||
`ocenka` float NOT NULL,
|
||
`pos` tinyint(4) NOT NULL,
|
||
PRIMARY KEY (`id`)
|
||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
|
||
$rez = $DB->QUR($sql);
|
||
$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['razde'].'` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`name` varchar(255) NOT NULL,
|
||
`descrip` TEXT NOT NULL,
|
||
`pos` tinyint(4) NOT NULL,
|
||
PRIMARY KEY (`id`)
|
||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
|
||
$rez = $DB->QUR($sql);
|
||
$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['grupps'].'` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`id_tests` int(11) NOT NULL,
|
||
`id_grupp` int(11) NOT NULL,
|
||
PRIMARY KEY (`id`)
|
||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
|
||
$rez = $DB->QUR($sql);
|
||
$sql = 'CREATE TABLE IF NOT EXISTS `'.$ST['dbpf'].'_test_users_otvet` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`data_c` int(11) NOT NULL,
|
||
`id_tests` int(11) NOT NULL,
|
||
`id_quest` int(11) NOT NULL,
|
||
`id_answer` int(11) NOT NULL,
|
||
`text_quest` TEXT NOT NULL,
|
||
`text_answer` TEXT NOT NULL,
|
||
`text_otvet` TEXT NOT NULL,
|
||
`ball` float NOT NULL,
|
||
`id_user` int(11) NOT NULL,
|
||
PRIMARY KEY (`id`)
|
||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
|
||
$rez = $DB->QUR($sql);
|
||
}
|
||
function test_get_grupps($teacher_id,$sel=array()){
|
||
GLOBAL $ST,$DB; $out=array();
|
||
$form['p']=array();
|
||
$sql1='SELECT g.sokr,g.kurs,g.fo,g.id FROM '.$ST['dbpf'].'_grupp as g,'.$ST['dbpf'].'_grupp_teachers as gt WHERE gt.id_teacher='.$teacher_id.' AND gt.id_grupp=g.id ORDER BY g.kurs,g.sokr';
|
||
$rez1=$DB->QUR_SEL($sql1); //echo '<pre>'.print_r($rez1,1).''.print_r($sel,1).'</pre>';
|
||
if($rez1){
|
||
foreach($rez1 as $key1 => $val1)if($key1){
|
||
$val1['sokr']=out_data_fu($val1['sokr']);
|
||
$val1['kurs']=out_data_fu($val1['kurs']);
|
||
$val1['fo']=out_data_fu($val1['fo']);
|
||
if(in_array($val1['id'],$sel)) $val1['sel']=1; else $val1['sel']=0;
|
||
$out[]=$val1;
|
||
}
|
||
}
|
||
return $out;
|
||
}
|
||
if($TS['view']=='teacher'){
|
||
if(isset($_POST['ques_id'])){//редаткирование вопроса
|
||
$out=array(); $out['rez']='';
|
||
//$out['rez']='<pre>'.print_r($_POST,1).'</pre>';
|
||
//$out['rez']='<script type="text/javascript">alert("'.print_r($_POST,1).'")</script>';
|
||
$id_test = (int)$_POST['test_id'];
|
||
$quest['ques_id'] = (int)$_POST['ques_id'];
|
||
$quest['tip'] =0; if($_POST['tip']!='')$quest['tip'] = (int)$_POST['tip'];
|
||
$quest['text_q'] = addslashes($_POST['text_q']);
|
||
$quest['ocenka'] =0; if($_POST['ocenka']!='') $quest['ocenka'] = trim(str_replace(',','.',$_POST['ocenka']));
|
||
$quest['random_a'] = 0; if(isset($_POST['random_a'])) $quest['random_a'] = 1;
|
||
$quest['test'] = 0; if(isset($_POST['test'])) $quest['test'] = 1;
|
||
$quest['pos'] =0; if($_POST['pos']!='') $quest['pos'] = (int)$_POST['pos'];
|
||
$ianswer=false;
|
||
if(isset($_POST['question_dele'])){//удалеям вопросы и ответы
|
||
$sql = 'DELETE FROM '.$TB['quest'].' WHERE id='.$quest['ques_id'].' AND id_tests='.$id_test.' LIMIT 1';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']) { $out['rez'].='Вопрос '.$quest['ques_id'].' удален!<br>'; $out['qdele'][]=$quest['ques_id']; } else $out['rez'].='Вопрос '.$quest['ques_id'].' не удален! Ошибка БД.<br>';
|
||
$sql = 'DELETE FROM '.$TB['answe'].' WHERE id_questions='.$quest['ques_id'].';';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']) { $out['rez'].='Ответы вопроса '.$quest['ques_id'].' удалены!<br>'; } else $out['rez'].='Ответы вопроса '.$quest['ques_id'].' не удалены! Ошибка БД.<br>';
|
||
}else{//редактируем добавляем вопросы и ответы
|
||
if($quest['ques_id']>0){
|
||
$sql = 'UPDATE '.$TB['quest'].' SET text_q="'.$quest['text_q'].'",ocenka='.$quest['ocenka'].',tip='.$quest['tip'].',random_a='.$quest['random_a'].',tests='.$quest['test'].',pos='.$quest['pos'].' WHERE id='.$quest['ques_id'].' LIMIT 1';
|
||
$rez = $DB->QUR($sql); //$out['rez'].=$sql.'<bR>';
|
||
if(!$rez['err']) { $out['rez'].='Вопрос сохранен!<br>'; $ianswer=true; $id_questions = $quest['ques_id']; } else $out['rez'].='Вопрос не сохранен! Ошибка БД.<br>';
|
||
}else{
|
||
$sql = 'INSERT INTO '.$TB['quest'].' VALUES (0,'.$id_test.',"'.$quest['text_q'].'",'.$quest['ocenka'].','.$quest['tip'].','.$quest['random_a'].','.$quest['test'].','.$quest['pos'].')';
|
||
$rez = $DB->QUR($sql); //$out['rez'].=$sql.'<bR>';
|
||
if(!$rez['err']) { $out['rez'].='Вопрос добавлен!<br>'; $ianswer=true; $id_questions = mysql_insert_id(); } else $out['rez'].='Вопрос не добавлен! Ошибка БД.<br>';
|
||
}
|
||
if($ianswer){//вставляем/редактируем ответы
|
||
foreach($_POST['text_a'] as $id_answer => $v){
|
||
if(isset($_POST['answer_dele'][$id_answer])){//удаляем
|
||
$sql = 'DELETE FROM '.$TB['answe'].' WHERE id='.$id_answer.' AND id_questions='.$id_questions.' LIMIT 1';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']) { $out['rez'].='Ответ '.$id_answer.' удален!<br>'; $out['adele'][]=$id_answer; } else $out['rez'].='Ответ '.$id_answer.' не удален! Ошибка БД.<br>';
|
||
}else{//редаткируем или добавляем
|
||
$text_a = addslashes($_POST['text_a'][$id_answer]); //$out['rez'].=$id_answer.' - '.$v.'<bR>';
|
||
$ocenka =0; if($_POST['tip_a'][$id_answer]!='') $ocenka = trim(str_replace(',','.',$_POST['tip_a'][$id_answer]));
|
||
$pos =0; if($_POST['pos_a'][$id_answer]!='') $pos = (int)$_POST['pos_a'][$id_answer];
|
||
if($id_answer>0){
|
||
$sql = 'UPDATE '.$TB['answe'].' SET text_a="'.$text_a.'",ocenka='.$ocenka.',pos='.$pos.' WHERE id='.$id_answer.' AND id_questions='.$id_questions.' LIMIT 1';
|
||
$rez = $DB->QUR($sql); //$out['rez'].=$sql.'<bR>';
|
||
if(!$rez['err']) { $out['rez'].='Ответ '.$id_answer.' сохранен!<br>'; } else $out['rez'].='Ответ '.$id_answer.' не сохранен! Ошибка БД.<br>';
|
||
}else{
|
||
$sql = 'INSERT INTO '.$TB['answe'].' VALUES (0,'.$id_questions.',"'.$text_a.'",'.$ocenka.','.$pos.')';
|
||
$rez = $DB->QUR($sql); //$out['rez'].=$sql.'<bR>';
|
||
if(!$rez['err']) { $out['rez'].='Ответ добавлен!<br>'; $ianswer=true; } else $out['rez'].='Ответ не добавлен! Ошибка БД.<br>';
|
||
//при добавлении новых вопросов после 2го текстареа не отображается нормально и тексты ответов не сохраняеются(
|
||
//решил сделать редирект на эту же страницу
|
||
//header("refresh:5;url=/teach/tests/questions/".$id_test."/");
|
||
//надо в jquery делать
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//$out['rez'] .= '<pre>'.print_r($_POST,1).'</pre>';
|
||
echo json_encode($out);
|
||
exit();
|
||
}
|
||
$regim = 'show';
|
||
$mess=array();
|
||
//$mess['msg'][]='<pre>'.print_r($_POST,1).'</pre>';
|
||
//$mess['msg'][]='<pre>'.print_r($_GET,1).'</pre>';
|
||
|
||
if(isset($_POST['edit'])||isset($_POST['add'])){
|
||
$id_razdel = (int)$_POST['id_razdel'];
|
||
$name = addslashes($_POST['name']);
|
||
$descrip = addslashes($_POST['descrip']);
|
||
if(isset($_POST['status'])) $status = 1; else $status = 0;
|
||
if(isset($_POST['random_q'])) $random_q = 1; else $random_q = 0;
|
||
if(isset($_POST['test'])) $testc = 1; else $testc = 0;
|
||
if(isset($_POST['copy'])) $copy = 1; else $copy = 0;
|
||
if($_POST['data_testa']!='') {
|
||
$t1=explode(' ',$_POST['data_testa']);
|
||
$t2=explode(':',$t1[0]);
|
||
$t3=explode('.',$t1[1]);
|
||
$data_testa = mktime($t2[0],$t2[1],0,$t3[1],$t3[0],$t3[2]);
|
||
}else $data_testa=0;
|
||
|
||
if(trim($_POST['new_razdel'])!=''){
|
||
$new_razdel = addslashes(trim($_POST['new_razdel']));
|
||
$sql = 'SELECT * FROM '.$TB['razde'].' WHERE name="'.$new_razdel.'"';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
$id_razdel = $rez[1]['id'];
|
||
}else{
|
||
$sql = 'INSERT INTO '.$TB['razde'].' VALUES(0,"'.$new_razdel.'","",0)';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']){ $id_razdel = mysql_insert_id(); }else{ $id_razdel = 0; }
|
||
}
|
||
}
|
||
$grupps=array();
|
||
if(isset($_POST['grupps'])){
|
||
foreach($_POST['grupps'] as $k => $v){
|
||
$grupps[]=$v;
|
||
}
|
||
}
|
||
if(isset($_POST['edit'])){
|
||
$id = (int)$_POST['id'];
|
||
$sql = 'UPDATE '.$TB['tests'].' SET name="'.$name.'",descrip="'.$descrip.'",status='.$status.',random_q='.$random_q.',tests='.$testc.',copy='.$copy.',id_razdel='.$id_razdel.',data_testa='.$data_testa.' WHERE id='.$id.' AND id_user='.$_SESSION['user']['teacher']['id'].' LIMIT 1';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']){
|
||
$mess[]='Тест успешно изменен'; save_logs('Тест обновлен '.$id.' : '.$name.'');
|
||
$sql2 = 'DELETE FROM '.$TB['grupps'].' WHERE id_tests='.$id.'';
|
||
$rez2 = $DB->QUR($sql2);
|
||
foreach($grupps as $k => $v){
|
||
$sql = 'INSERT INTO '.$TB['grupps'].' VALUES(0,'.$id.','.$v.')';
|
||
$rez = $DB->QUR($sql);
|
||
}
|
||
}else{ $mess[]='Тест не изменен, ошибка БД'; }
|
||
}
|
||
if(isset($_POST['add'])){
|
||
$sql = 'INSERT INTO '.$TB['tests'].' VALUES(0,'.time().','.$_SESSION['user']['teacher']['id'].','.$id_razdel.',"'.$name.'","'.$descrip.'",'.$status.','.$random_q.','.$testc.','.$data_testa.','.$copy.')';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']){
|
||
$id_test = mysql_insert_id();
|
||
$mess[]='Тест успешно добавлен'; save_logs('Тест добавлен '.$id_test.' : '.$name.'');
|
||
foreach($grupps as $k => $v){
|
||
$sql = 'INSERT INTO '.$TB['grupps'].' VALUES(0,'.$id_test.','.$v.')';
|
||
$rez = $DB->QUR($sql);
|
||
}
|
||
}else{ $mess[]='Тест не добавлен, ошибка БД'; }
|
||
}
|
||
}
|
||
if(isset($_GET['des'])){
|
||
if($_GET['des']=='result'){
|
||
$regim = 'result';
|
||
$id_test = (int)$_GET['id'];
|
||
$rtests=array();
|
||
$sql = 'SELECT tuo.id_user,g.sokr,g.kurs,g.fo,s.num_grupp,u.fio FROM '.$ST['dbpf'].'_test_users_otvet as tuo,'.$ST['dbpf'].'_students as s,'.$ST['dbpf'].'_grupp as g,'.$ST['dbpf'].'_users as u WHERE tuo.id_tests='.$id_test.' AND s.id_user=tuo.id_user AND g.id=s.id_grupp AND u.id=tuo.id_user GROUP BY tuo.id_user LIMIT 25';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
foreach($rez as $key => $val)if($key){//обходим каждого юзера
|
||
//выберем ответы по дате создания
|
||
//$sql1 = 'SELECT data_c FROM '.$ST['dbpf'].'_test_users_otvet WHERE id_tests='.$id_test.' AND id_user='.$val['id_user'].' GROUP BY data_c ORDER BY data_c DESC';
|
||
$sql1 = 'SELECT data_c, id_user FROM '.$ST['dbpf'].'_test_users_otvet WHERE id_tests='.$id_test.' AND id_user='.$val['id_user'].' GROUP BY id_user ORDER BY data_c DESC';
|
||
$rez1 = $DB->QUR_SEL($sql1);
|
||
if($rez1){
|
||
foreach($rez1 as $k1 => $v1)if($k1){
|
||
$test=array(); $kol_a=0; $balls=0;
|
||
|
||
$sql20 = 'SELECT COUNT(id) as kol, SUM(ocenka) as allocenka FROM '.$ST['dbpf'].'_test_questions WHERE id_tests='.$id_test.'';
|
||
$rez20 = $DB->QUR_SEL($sql20);
|
||
$allocenka=$rez20[1]['allocenka'];
|
||
if($allocenka==0){//если у вопросов нет баллов
|
||
$allocenka=$rez20[1]['kol'];
|
||
}
|
||
//echo $rez20[1]['allocenka'].'-'.$rez20[1]['kol'].'<br>';
|
||
//$mess['msg'][]='<pre>'.print_r($rez20,1).'</pre>';
|
||
$sql2 = 'SELECT * FROM '.$ST['dbpf'].'_test_users_otvet WHERE id_tests='.$id_test.' AND id_user='.$val['id_user'].' AND data_c='.$v1['data_c'].' ORDER BY data_c DESC';
|
||
$rez2 = $DB->QUR_SEL($sql2);
|
||
//$mess['msg'][]='<pre>'.print_r($rez2,1).'</pre>';
|
||
if($rez2){
|
||
foreach($rez2 as $k2 => $v2)if($k2){//обходим все ответы в тесте для юзера
|
||
$data_c = date('H:i d.m.Y',$v2['data_c']);
|
||
$kol_a++;
|
||
$sql3 = 'SELECT tip,ocenka FROM '.$ST['dbpf'].'_test_questions WHERE id='.$v2['id_quest'].'';
|
||
$rez3 = $DB->QUR_SEL($sql3);//узнаем кол-во баллов за вопрос
|
||
//$mess['msg'][]='<pre>'.print_r($rez3,1).'</pre>';
|
||
if($rez3[1]['tip']==0) {
|
||
//08042020 - добавил
|
||
if($rez3[1]['ocenka']==0){//вопрос без балла
|
||
$ocq = $v2['ball'];
|
||
}else{
|
||
$ocq = $rez3[1]['ocenka'];
|
||
}
|
||
}
|
||
if($rez3[1]['tip']==1) {//множественный ответ
|
||
/*if($rez3[1]['ocenka']!=0){
|
||
//делить балл на правильные ответы
|
||
$sql4 = 'SELECT id FROM '.$ST['dbpf'].'_test_answers WHERE id_questions='.$v2['id_quest'].'';
|
||
$rez4 = $DB->QUR_SEL($sql4);
|
||
if($rez4) {
|
||
$ocq = round($rez3[1]['ocenka']/$rez4[0],0);
|
||
//$ocq = $rez3[1]['ocenka'];
|
||
}
|
||
$ocq = $rez3[1]['ocenka'];//несколько раз учитывается(((
|
||
}else{
|
||
$ocq = $v2['ball'];
|
||
}*/
|
||
if($rez3[1]['ocenka']!=0){
|
||
$ocquest = $rez3[1]['ocenka'];
|
||
}else{
|
||
$ocquest = 1;
|
||
}
|
||
|
||
$kol_prav=0;//кол-во правильных ответов
|
||
$sql21 = 'SELECT COUNT(id) as kol FROM '.$ST['dbpf'].'_test_answers WHERE id_questions='.$v2['id_quest'].' AND ocenka=0';
|
||
$rez21 = $DB->QUR_SEL($sql21);
|
||
if($rez21){ $kol_prav=$rez21[1]['kol']; }
|
||
if($kol_prav!=0){
|
||
$ocq = round($ocquest/$kol_prav,0);
|
||
}else{ $ocq=0; }
|
||
}
|
||
if($rez3[1]['tip']==2) {
|
||
//08042020 - добавил
|
||
if($rez3[1]['ocenka']==0){//вопрос без балла
|
||
$ocq = $v2['ball'];
|
||
}else{
|
||
$ocq = $rez3[1]['ocenka'];
|
||
}
|
||
}
|
||
if($rez3[1]['tip']==3) {
|
||
//08042020 - добавил
|
||
if($rez3[1]['ocenka']==0){//вопрос без балла
|
||
$ocq = $v2['ball'];
|
||
}else{
|
||
$ocq = $rez3[1]['ocenka'];
|
||
}
|
||
}//тут балы не надо учитывать(
|
||
|
||
//узнаем правильно ли отвтеил
|
||
$sql4 = 'SELECT ocenka FROM '.$ST['dbpf'].'_test_answers WHERE id='.$v2['id_answer'].'';
|
||
$rez4 = $DB->QUR_SEL($sql4);
|
||
if($rez4[1]['ocenka']==0) {//если правильный ответ
|
||
$balls+=$ocq;
|
||
}else{
|
||
if($rez3[1]['tip']==1){
|
||
$balls+=-$ocq;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//считаем общее количество верных ответов
|
||
$balll = 0;
|
||
$sql_ball = 'SELECT * FROM '.$ST['dbpf'].'_test_users_otvet WHERE id_tests = "'.$id_test.'" AND id_user='.$val['id_user'].' ';
|
||
$rez_ball = $DB->QUR_SEL($sql_ball);
|
||
foreach($rez_ball as $key_ball => $v_b)if($key_ball){
|
||
$balll += $v_b['ball'];
|
||
}
|
||
|
||
|
||
$val['tests'][$k1]['data_c']=date('H:i d.m.Y',$v1['data_c']);
|
||
//$mess['msg'][]='<pre>'.$allocenka.'-'.$balls.'</pre>';
|
||
//закоментил условие 08042020
|
||
//if($allocenka<$balls) $val['tests'][$k1]['balls'] = $allocenka;
|
||
//else $val['tests'][$k1]['balls'] = $balls;
|
||
//$val['tests'][$k1]['balls'] = $balls; было
|
||
$val['tests'][$k1]['balls'] = round($balll,2);
|
||
$val['tests'][$k1]['balls_all'] = $allocenka;
|
||
}
|
||
}
|
||
$rtests[]=$val;
|
||
}
|
||
}
|
||
//$mess['msg'][]='<pre>'.print_r($rtests,1).'</pre>';
|
||
$smarty->assign('id_test',$id_test);
|
||
$smarty->assign('rtests',$rtests);
|
||
}
|
||
if($_GET['des']=='questions'){
|
||
|
||
$id_test = (int)$_GET['id'];
|
||
$file='/upload/tests/'.$_SESSION['user']['teacher']['id'].'/'.$id_test; if(!file_exists($file)) mkdir($file,0777,1);
|
||
$_SESSION['niceditor']['path1'] = $_SERVER['DOCUMENT_ROOT'].$file;
|
||
if(!file_exists($_SESSION['niceditor']['path1'])) mkdir($_SESSION['niceditor']['path1'],0777,1);
|
||
$_SESSION['niceditor']['path2'] = $file;
|
||
$regim = 'questions';
|
||
$sql = 'SELECT * FROM '.$TB['tests'].' WHERE id='.$id_test.' AND id_user='.$_SESSION['user']['teacher']['id'].'';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
$questions['ques'] = select_test_questions($id_test);
|
||
$questions['test'] = $rez[1];
|
||
//echo '<prE>'.print_r($questions,1).'</pre>';
|
||
$smarty->assign('questions',$questions);
|
||
}else{
|
||
$mess[]='Нет доступа к тесту.';
|
||
}
|
||
}
|
||
if($_GET['des']=='exportf'){
|
||
$regim = 'export';
|
||
$file = $_GET['file'];
|
||
$dfile = $uploaddir.$file;
|
||
$tfile = $tmpdir.$file;
|
||
if(!file_exists($tfile)) {
|
||
mkdir($tfile);
|
||
$zip = new ZipArchive();
|
||
if ($zip->open($dfile) === true) {
|
||
$zip->extractTo($tfile);
|
||
$zip->close();
|
||
}else $mess[]='Архива не существует!';
|
||
}else $mess[]='архив уже распакован';
|
||
$xfile = $tfile.'/moodle.xml';
|
||
$mess[]='Начинаем работать с '.$xfile;
|
||
if(file_exists($xfile)){
|
||
$mess[]='разбираем xml';
|
||
$xml = simplexml_load_file($xfile);
|
||
|
||
$mess[]='НАЗВАНИЕ РАЗДЕЛА: '.$xml->COURSE->HEADER->CATEGORY->NAME;
|
||
$arr['name'] = $xml->COURSE->HEADER->CATEGORY->NAME;
|
||
$arr['descrip']='';
|
||
if($xml->COURSE->HEADER->FULLNAME!='') $arr['descrip'] .= 'Полное название: '.$xml->COURSE->HEADER->FULLNAME;
|
||
if($xml->COURSE->HEADER->SHORTNAME!='') $arr['descrip'] .= '<br>Краткое название: '.$xml->COURSE->HEADER->SHORTNAME;
|
||
$tcr = test_create_razdel($arr);
|
||
if(!$tcr['err']){
|
||
save_logs('Тест экспорт создание раздела успех '.$arr['name'].'');
|
||
//обход модулей
|
||
foreach ($xml->COURSE->MODULES->MOD as $MOD) {
|
||
if($MOD->MODTYPE == 'questionnaire'){//для опроса качества!
|
||
$mess[]='ТЕСТ: <b>'.$MOD->NAME.'</b> '.$MOD->SUMMARY;
|
||
$arr['name'] = $MOD->NAME;
|
||
$arr['descrip'] = $MOD->SUMMARY;
|
||
$arr['random_q'] = 0;
|
||
$arr['id_razdel'] = $tcr['id'];
|
||
$tct = test_create_test($arr);
|
||
if(!$tct['err']){
|
||
save_logs('Тест экспорт создание теста-опроскачества успех '.$arr['name'].'-'.$arr['descrip']);
|
||
foreach ($MOD->SURVEY->QUESTION as $QUESTION) {
|
||
//$mess[]='ВОПРОС: <u>'.$QUESTION->CONTENT.'</u>';
|
||
$arr['text_q'] = $QUESTION->CONTENT;
|
||
$arr['pos'] = $QUESTION->POSITION;
|
||
$arr['ocenka'] = $QUESTION->LENGTH;
|
||
$arr['id_tests'] = $tct['id'];
|
||
$arr['tip'] = 3;
|
||
$arr['random_a'] =0;
|
||
$tcq = test_create_quest($arr);
|
||
if(!$tcq['err']){
|
||
save_logs('Тест экспорт создание вопроса-опроскачества успех '.$arr['text_q']);
|
||
if(isset($QUESTION->QUESTION_CHOICE)){
|
||
foreach ($QUESTION->QUESTION_CHOICE as $QUESTION_CHOICE) {
|
||
//$mess[]=' <i>'.$QUESTION_CHOICE->CONTENT.'</i>';
|
||
$arr['id_questions'] = $tcq['id'];
|
||
$arr['text_a'] = $QUESTION_CHOICE->CONTENT;
|
||
$arr['ocenka'] = $QUESTION->LENGTH;
|
||
$tca = test_create_answe($arr);
|
||
if($tca['err']) $mess[]=$tca['msg'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if($MOD->MODTYPE == 'questionnaire'){//для опросников надо реализовывать (((
|
||
}
|
||
if($MOD->MODTYPE == 'quiz'){//для тестов
|
||
$mess[]='ТЕСТ: <b>'.$MOD->NAME.'</b>';
|
||
$arr['name'] = $MOD->NAME;
|
||
$arr['descrip'] = $MOD->INTRO;
|
||
$arr['id_razdel'] = $tcr['id'];
|
||
$tct = test_create_test($arr);
|
||
//$mess[]=$tct['msg'];
|
||
if(!$tct['err']){
|
||
save_logs('Тест экспорт создание теста успех '.$arr['name'].'');
|
||
//тут вопросы хранятся по номерам QUESTION_INSTANCES>
|
||
foreach ($MOD->QUESTION_INSTANCES->QUESTION_INSTANCE as $QUESTION_INSTANCE) {
|
||
$mess[]='ВОПРОС №: <u>'.$QUESTION_INSTANCE->QUESTION.'</u> Оценка:'.$QUESTION_INSTANCE->GRADE.' | ';
|
||
foreach ($xml->COURSE->QUESTION_CATEGORIES->QUESTION_CATEGORY as $QUESTION_CATEGORY) {
|
||
foreach ($QUESTION_CATEGORY->QUESTIONS->QUESTION as $QUESTION) {
|
||
if((int)$QUESTION->ID == (int)$QUESTION_INSTANCE->QUESTION){
|
||
$mess[]='<u>'.$QUESTION->QUESTIONTEXT.'</u>';
|
||
$arr['text_q'] = $QUESTION->QUESTIONTEXT;
|
||
$arr['ocenka'] = $QUESTION_INSTANCE->GRADE;
|
||
$arr['id_tests'] = $tct['id'];
|
||
if($QUESTION->QTYPE=='multichoice') $arr['tip'] = 1;
|
||
if($QUESTION->QTYPE=='numerical') $arr['tip'] = 0;
|
||
if($QUESTION->QTYPE=='match') $arr['tip'] = 0;
|
||
if($QUESTION->QTYPE=='truefalse') $arr['tip'] = 0;
|
||
if($QUESTION->QTYPE=='shortanswer') $arr['tip'] = 2;
|
||
if($QUESTION->QTYPE=='essay') $arr['tip'] = 2;
|
||
$tcq = test_create_quest($arr);
|
||
if(!$tcq['err']){
|
||
save_logs('Тест экспорт создание вопроса успех '.$arr['text_q'].'');
|
||
foreach ($QUESTION->ANSWERS->ANSWER as $ANSWER) {
|
||
//$mess[]=' '.$ANSWER->ANSWER_TEXT.' Оценка: '.$ANSWER->FRACTION;
|
||
$arr['id_questions'] = $tcq['id'];
|
||
$arr['text_a'] = $ANSWER->ANSWER_TEXT;
|
||
$arr['ocenka'] = $ANSWER->FRACTION;
|
||
$tca = test_create_answe($arr);
|
||
if($tca['err']) $mess[]=$tca['msg'];
|
||
}
|
||
}else { $mess[]=$tcq['msg']; }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}else{ $mess[]=$tct['msg']; }
|
||
}
|
||
}
|
||
}else { $mess[]=$tcr['msg']; }
|
||
}else $mess[]= 'файла moodle.xml нет!<br>';
|
||
}
|
||
if($_GET['des']=='export'){
|
||
$regim = 'export';
|
||
if(isset($_POST['upload'])){
|
||
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
|
||
if(!file_exists($uploadfile)){
|
||
//if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
|
||
if ($SYSTEMclass->sysUPLOAD($_FILES['userfile']['tmp_name'], $uploadfile)) {
|
||
$mess[]='Файл корректен и был успешно загружен.';
|
||
save_logs('Тест экспорт файла успех '.$uploadfile.'');
|
||
} else {
|
||
$mess[]='Возможная атака с помощью файловой загрузки!';
|
||
}
|
||
}else $mess[]='файл уже существует';
|
||
}
|
||
}
|
||
if($_GET['des']=='export'||$_GET['des']=='exportf'){
|
||
//отобразим загруженные файлы
|
||
$f = scandir($uploaddir); $files = array();
|
||
foreach($f as $k => $v)if($v!='.'&&$v!='..'){
|
||
$files[$k] = $v;
|
||
}
|
||
$smarty->assign('files',$files);
|
||
}
|
||
if($_GET['des']=='add'){
|
||
$regim = 'aded';
|
||
$test['title'] = 'Добавление теста';
|
||
$test['regim'] = 'add';
|
||
|
||
$test['grupps'] = test_get_grupps($_SESSION['user']['teacher']['id']);
|
||
|
||
$smarty->assign('test',$test);
|
||
$smarty->assign('razdels',select_razdels(0));
|
||
}
|
||
if($_GET['des']=='del'){
|
||
$regim = 'show';
|
||
$id = (int)$_GET['id'];
|
||
$sql0 = 'SELECT * FROM '.$ST['dbpf'].'_test_tests WHERE id='.$id.' AND id_user='.$_SESSION['user']['teacher']['id'].'';
|
||
$rez0 = $DB->QUR_SEL($sql0);
|
||
//echo '<pre>'.print_r($rez0,1).'</pre>';
|
||
if($rez0){
|
||
$sql = 'SELECT * FROM '.$ST['dbpf'].'_test_questions WHERE id_tests='.$id.'';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
//echo '<pre>'.print_r($rez,1).'</pre>';
|
||
if($rez){
|
||
foreach($rez as $key => $val)if($key){
|
||
$sql1='DELETE FROM '.$ST['dbpf'].'_test_answers WHERE id_questions='.$val['id'].'';
|
||
$DB->QUR_SEL($sql1);
|
||
}
|
||
$sql1='DELETE FROM '.$ST['dbpf'].'_test_questions WHERE id_tests='.$id.'';
|
||
$DB->QUR_SEL($sql1);
|
||
}else $mess[]='Запрошенных вопросов не существует!';
|
||
$sql1='DELETE FROM '.$ST['dbpf'].'_test_tests WHERE id='.$id.'';
|
||
$DB->QUR_SEL($sql1);
|
||
$mess[]='Тест и Вопросы с ответами удалены!';
|
||
}else $mess[]='Запрошенного теста не существует!';
|
||
}
|
||
if($_GET['des']=='edit'){
|
||
$regim = 'aded';
|
||
$id = (int)$_GET['id'];
|
||
$sql = 'SELECT * FROM '.$TB['tests'].' WHERE id_user='.$_SESSION['user']['teacher']['id'].' AND id='.$id.' LIMIT 1';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
$test=$rez[1];
|
||
$test['title'] = 'Редактирвоание теста';
|
||
$test['regim'] = 'edit';
|
||
$test['name'] = stripslashes($test['name']);
|
||
$test['descrip'] = stripslashes($test['descrip']);
|
||
if($test['data_testa']!=0) $test['data_testa'] = date('H:i d.m.Y',$test['data_testa']);
|
||
else $test['data_testa'] = '';
|
||
$tg=array();
|
||
$sql2 = 'SELECT * FROM '.$TB['grupps'].' WHERE id_tests='.$id.'';
|
||
$rez2 = $DB->QUR_SEL($sql2);
|
||
if($rez2){
|
||
foreach($rez2 as $k2 => $v2)if($k2){
|
||
//$tg[]=$v2['id_tests'];
|
||
$tg[]=$v2['id_grupp'];
|
||
}
|
||
}
|
||
$test['grupps'] = test_get_grupps($_SESSION['user']['teacher']['id'],$tg);
|
||
|
||
$smarty->assign('razdels',select_razdels($test['id_razdel']));
|
||
$smarty->assign('test',$test);
|
||
//$mess['msg'][]='<pre>'.print_r($test,1).'</pre>';
|
||
}
|
||
}
|
||
}else{
|
||
}
|
||
if($regim == 'show'){//отобразим все свои тесты
|
||
$regim='show';
|
||
$tests = select_my_tests();
|
||
$tests_ch = select_not_my_tests();
|
||
|
||
$smarty->assign('tests',$tests);
|
||
$smarty->assign('tests_ch',$tests_ch);
|
||
}
|
||
|
||
$smarty->assign('msg',$mess);
|
||
$smarty->assign('regim',$regim);
|
||
$maincontent = $smarty->fetch('tpl_teacher_tests.html');
|
||
}
|
||
|
||
function select_test_questions($id_test){
|
||
GLOBAL $ST,$DB,$TB; $out=array();
|
||
$sql = 'SELECT * FROM '.$TB['quest'].' WHERE id_tests='.$id_test.' ORDER BY pos';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
foreach($rez as $key => $val)if($key){
|
||
$val['text_q'] = htmlspecialchars(stripslashes($val['text_q']));
|
||
$rez1 = $DB->QUR_SEL('SELECT * FROM '.$TB['answe'].' WHERE id_questions='.$val['id'].' ORDER BY pos');
|
||
$val['answers']=array(); if($rez1){
|
||
foreach($rez1 as $k => $v)if($k){
|
||
$v['text_a'] = htmlspecialchars(stripslashes($v['text_a']));
|
||
$val['answers'][]=$v;
|
||
}
|
||
}
|
||
if($val['text_q']!='') $out[] = $val;
|
||
}
|
||
}
|
||
return $out;
|
||
}
|
||
|
||
function select_my_tests(){
|
||
GLOBAL $ST,$DB,$TB; $out=array();
|
||
$sql = 'SELECT * FROM '.$TB['tests'].' WHERE id_user='.$_SESSION['user']['teacher']['id'].'';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
foreach($rez as $key => $val)if($key){
|
||
$val['data_c'] = date('H:i d.m.Y',$val['data_c']);
|
||
$val['name'] = stripslashes($val['name']);
|
||
$val['descrip'] = stripslashes($val['descrip']);
|
||
$rez1 = $DB->QUR_SEL('SELECT name FROM '.$TB['razde'].' WHERE id='.$val['id_razdel']);
|
||
$val['razde']=''; if($rez1){ $val['razde']=$rez1[1]['name']; }
|
||
$rez1 = $DB->QUR_SEL('SELECT id FROM '.$TB['quest'].' WHERE id_tests='.$val['id']);
|
||
$val['questions']=0; if($rez1){ $val['questions']=$rez1[0]; }
|
||
$out[] = $val;
|
||
}
|
||
}
|
||
return $out;
|
||
}
|
||
|
||
function select_not_my_tests(){
|
||
GLOBAL $ST,$DB,$TB; $out=array();
|
||
$sql = 'SELECT * FROM '.$TB['tests'].' WHERE NOT(id_user='.$_SESSION['user']['teacher']['id'].') AND copy = 1 ORDER BY data_c DESC LIMIT 30';
|
||
//if search
|
||
if (isset($_POST['search_test'])) $sql = 'SELECT * FROM '.$TB['tests'].' WHERE name LIKE "%'.$_POST['name'].'%" AND copy = 1 ';
|
||
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
foreach($rez as $key => $val)if($key){
|
||
$val['data_c'] = date('H:i d.m.Y',$val['data_c']);
|
||
$val['name'] = stripslashes($val['name']);
|
||
$val['descrip'] = stripslashes($val['descrip']);
|
||
$rez1 = $DB->QUR_SEL('SELECT name FROM '.$TB['razde'].' WHERE id='.$val['id_razdel']);
|
||
$val['razde']=''; if($rez1){ $val['razde']=$rez1[1]['name']; }
|
||
$rez1 = $DB->QUR_SEL('SELECT id FROM '.$TB['quest'].' WHERE id_tests='.$val['id']);
|
||
$val['questions']=0; if($rez1){ $val['questions']=$rez1[0]; }
|
||
$user = get_teacher_user($val['id_user']);
|
||
$val['fio'] = $user['fio'];
|
||
|
||
$out[] = $val;
|
||
}
|
||
}
|
||
return $out;
|
||
}
|
||
|
||
function select_razdels($id){
|
||
GLOBAL $ST,$DB,$TB; $out=array();
|
||
$sql = 'SELECT * FROM '.$TB['razde'].' ORDER BY pos';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
foreach($rez as $key => $val)if($key){
|
||
$val['name'] = stripslashes($val['name']);//.'-'.$id.'='.$val['id'];
|
||
$val['descrip'] = stripslashes($val['descrip']);
|
||
if($id == $val['id']) $val['sel']=1; else $val['sel']=0;
|
||
$out[] = $val;
|
||
}
|
||
}
|
||
return $out;
|
||
}
|
||
|
||
function test_create_razdel($arr){
|
||
GLOBAL $ST,$DB,$TB; $out=array();
|
||
$arr['name'] = mysql_real_escape_string($arr['name']);
|
||
$arr['descrip'] = mysql_real_escape_string($arr['descrip']);
|
||
$sql = 'SELECT * FROM '.$TB['razde'].' WHERE name="'.$arr['name'].'"';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
$out['err'] = false;
|
||
$out['msg'] = 'Уже есть раздел '.$arr['name'].'';
|
||
$out['id'] = $rez[1]['id'];
|
||
}else{
|
||
$sql = 'INSERT INTO '.$TB['razde'].' VALUES(0,"'.$arr['name'].'","'.$arr['descrip'].'",0);';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']){
|
||
$out['err'] = false;
|
||
$out['msg'] = 'Создали раздел '.$arr['name'].'';
|
||
$out['id'] = mysql_insert_id();
|
||
}else{
|
||
$out['err'] = true;
|
||
$out['msg'] = 'Ошибка БД при создании раздела';
|
||
$out['id'] = 0;
|
||
}
|
||
}
|
||
return $out;
|
||
}
|
||
function test_create_test($arr){
|
||
GLOBAL $ST,$DB,$TB; $out=array();
|
||
if(!isset($arr['random_q'])) $arr['random_q']=1;
|
||
$arr['name'] = mysql_real_escape_string($arr['name']);
|
||
$sql = 'SELECT * FROM '.$TB['tests'].' WHERE name="'.$arr['name'].'" AND id_razdel='.$arr['id_razdel'].'';
|
||
$rez = $DB->QUR_SEL($sql); //$out['msg'] = $sql.'-'.mysql_error();
|
||
if($rez){
|
||
$out['err'] = false;
|
||
$out['msg'] = 'Уже есть тест '.$arr['name'].'';
|
||
$out['id'] = $rez[1]['id'];
|
||
}else{
|
||
$sql = 'INSERT INTO '.$TB['tests'].' VALUES(0,'.time().','.$_SESSION['user']['teacher']['id'].','.$arr['id_razdel'].',"'.$arr['name'].'","'.$arr['descrip'].'",0,1,0,0);';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']){
|
||
$out['err'] = false;
|
||
$out['msg'] = 'Создали тест '.$arr['name'].'';
|
||
$out['id'] = mysql_insert_id();
|
||
}else{
|
||
$out['err'] = true;
|
||
$out['msg'] = 'Ошибка БД при создании теста';
|
||
$out['id'] = 0;
|
||
}
|
||
}
|
||
return $out;
|
||
}
|
||
function test_create_quest($arr){
|
||
GLOBAL $ST,$DB,$TB; $out=array();
|
||
if(!isset($arr['pos'])) $arr['pos']=0;
|
||
if(!isset($arr['random_a'])) $arr['random_a']=1;
|
||
$arr['text_q'] = mysql_real_escape_string($arr['text_q']);
|
||
$sql = 'SELECT * FROM '.$TB['quest'].' WHERE text_q="'.$arr['text_q'].'" AND id_tests='.$arr['id_tests'].'';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
$out['err'] = false;
|
||
$out['msg'] = 'Уже есть вопрос '.$arr['name'].'';
|
||
$out['id'] = $rez[1]['id'];
|
||
}else{
|
||
$sql = 'INSERT INTO '.$TB['quest'].' VALUES(0,'.$arr['id_tests'].',"'.$arr['text_q'].'",'.$arr['ocenka'].','.$arr['tip'].',1,0,'.$arr['pos'].');';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']){
|
||
$out['err'] = false;
|
||
$out['msg'] = 'Создали вопрос '.$arr['text_q'].'';
|
||
$out['id'] = mysql_insert_id();
|
||
}else{
|
||
$out['err'] = true;
|
||
$out['msg'] = 'Ошибка БД при создании вопроса';
|
||
$out['id'] = 0;
|
||
}
|
||
}
|
||
return $out;
|
||
}
|
||
function test_create_answe($arr){
|
||
GLOBAL $ST,$DB,$TB; $out=array();
|
||
$arr['text_a'] = mysql_real_escape_string($arr['text_a']);
|
||
$sql = 'SELECT * FROM '.$TB['answe'].' WHERE text_a="'.$arr['text_a'].'" AND id_questions='.$arr['id_questions'].'';
|
||
$rez = $DB->QUR_SEL($sql);
|
||
if($rez){
|
||
$out['err'] = false;
|
||
$out['msg'] = 'Уже есть ответ '.$arr['name'].'';
|
||
$out['id'] = $rez[1]['id'];
|
||
}else{
|
||
$sql = 'INSERT INTO '.$TB['answe'].' VALUES(0,'.$arr['id_questions'].',"'.$arr['text_a'].'",'.$arr['ocenka'].',0);';
|
||
$rez = $DB->QUR($sql);
|
||
if(!$rez['err']){
|
||
$out['err'] = false;
|
||
$out['msg'] = 'Создали ответ '.$arr['text_q'].'';
|
||
$out['id'] = mysql_insert_id();
|
||
}else{
|
||
$out['err'] = true;
|
||
$out['msg'] = 'Ошибка БД при создании ответа';
|
||
$out['id'] = 0;
|
||
}
|
||
}
|
||
return $out;
|
||
}
|