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 '
'.print_r($rez1,1).''.print_r($sel,1).''; 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']='
'.print_r($_POST,1).''; //$out['rez']=''; $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'].' удален!
'.print_r($_POST,1).''; echo json_encode($out); exit(); } $regim = 'show'; $mess=array(); //$mess['msg'][]='
'.print_r($_POST,1).''; //$mess['msg'][]='
'.print_r($_GET,1).''; 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'].'
'.print_r($rez20,1).''; $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'][]='
'.print_r($rez2,1).''; 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'][]='
'.print_r($rez3,1).''; 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'][]='
'.$allocenka.'-'.$balls.''; //закоментил условие 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'][]='
'.print_r($rtests,1).''; $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 '
'.print_r($questions,1).''; $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'] .= '
'.print_r($rez0,1).''; if($rez0){ $sql = 'SELECT * FROM '.$ST['dbpf'].'_test_questions WHERE id_tests='.$id.''; $rez = $DB->QUR_SEL($sql); //echo '
'.print_r($rez,1).''; 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'][]='
'.print_r($test,1).''; } } }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; }