EIOS/rabprog/inc/class_DisciplinsPrepodsChan...

125 lines
5.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class class_DisciplinsPrepodsChange{
private $DB=null;
private $TUchebplans='';
private $TUchebplansPrepod='';
private $Tusers='';
function __construct(){
GLOBAL $DB,$ST;
$this->DB = $DB;
$this->TUchebplans = $ST['dbpf'].'_fshp_uchebplans';
$this->TUchebplansPrepod = $ST['dbpf'].'_fshp_disciplin_prepod';
$this->Tusers = $ST['dbpf'].'_users';
}
public function HTML(){
GLOBAL $WorkDIR;
$CHPU = new class_CHPU($WorkDIR);
$URLS = $CHPU->uri();
$smartyC = new class_smarty();
$smarty = $smartyC->config(__DIR__.'\..\tpl');
//обработка АЯКС запросов
if(isset($_POST['ajdes'])){
header('Content-Type: application/json; charset=utf-8');
$out=array();
//Сохранение преподавателя к дисциплине
//if($_POST['ajdes']=='SavePrepod'){
// $id_disc=(int)$_POST['id_disc'];
// $id_prepod=(int)$_POST['id_prepod'];
// $smena=$_POST['smena'];
// $out = $this->Disciplin_Save_Prepod($id_disc,$id_prepod,$smena);
//}
echo json_encode($out);
exit();
}
$view = 'all';
$out = array('name'=>'Дисциплины','body'=>'');
if(isset($URLS[1])){
$id = 0; if(isset($URLS[2])) $id = (int)$URLS[2];
if($URLS[1]=='confirm'){
$sql = 'SELECT * FROM '.$this->TUchebplansPrepod.' WHERE id='.$id.' LIMIT 1';
$rez = $this->DB->QUR_SEL($sql);
if(!$rez['err']&&$rez['kol']){
if($rez['rez'][0]['id_prepod']==0){//Указан пустой препод!
$rez = $this->DB->QUR('DELETE FROM '.$this->TUchebplansPrepod.' WHERE id_uchebplans='.$rez['rez'][0]['id_uchebplans']);
}else {
$descrip = $rez['rez'][0]['descrip'] . ' : одобрено ' . date('H:i d.m.Y') . ' | ' . $_SESSION['user']['fio'];
$sql = 'UPDATE ' . $this->TUchebplansPrepod . ' SET descrip="' . $descrip . '", status=1 WHERE id=' . $id . ' LIMIT 1';
$rez = $this->DB->QUR($sql);
}
}
}
if($URLS[1]=='dele'){
$sql = 'SELECT * FROM '.$this->TUchebplansPrepod.' WHERE id='.$id.' LIMIT 1';
$rez = $this->DB->QUR_SEL($sql);
if(!$rez['err']&&$rez['kol']){
$sql = 'DELETE FROM '.$this->TUchebplansPrepod.' WHERE id='.$id.' LIMIT 1';
$rez = $this->DB->QUR($sql);
}
}
}
if(!isset($URLS[1])||$URLS[1]=='all') {
$dis = $this->Disciplins();
$smarty->assign('DISCIPS', $dis['items']);
$smarty->assign('view',$view);
$out['body'] = $smarty->fetch('page_disciplinsprepodschange.html');
}
return $out;
}
//подбираем дисциплины у которых менялся препод
public function Disciplins(){
$out=array();
$sql = 'SELECT up.id_uchebplans,upl.index1,upl.name,upl.kaf_kod,upl.kaf_name FROM '.$this->TUchebplans.' as upl,'.$this->TUchebplansPrepod.' as up WHERE upl.id=up.id_uchebplans AND up.status=0 ORDER BY up.data_c DESC';
$rez = $this->DB->QUR_SEL($sql);
//echo $sql.'<pre>'.print_r($rez,1).'</pre>';exit();
if(!$rez['err']&&$rez['kol']){
foreach ($rez['rez'] as $k => $v){
$v['history'] = $this->DisciplinsHistory($v['id_uchebplans']);
$out[] = $v;
}
}
return array('items'=>$out);
}
//подбираем дисциплины историю изменений
public function DisciplinsHistory($id_uchebplans){
$out=array();
//$sql = 'SELECT up.id,up.data_c,up.descrip,up.status,u.fio FROM '.$this->TUchebplansPrepod.' as up,'.$this->Tusers.' as u WHERE u.id=up.id_prepod AND up.id_uchebplans='.$id_uchebplans.' ORDER BY up.data_c DESC';
//$rez = $this->DB->QUR_SEL($sql);
//if(!$rez['err']&&$rez['kol']){
// foreach ($rez['rez'] as $k => $v){
// $out[] = $v;
// }
//}
//if(!count($out)){
$sql = 'SELECT up.id,up.data_c,up.descrip,up.status,u.fio FROM '.$this->TUchebplansPrepod.' as up,'.$this->Tusers.' as u WHERE u.id=up.id_prepod AND up.id_uchebplans='.$id_uchebplans.' ORDER BY up.data_c DESC';
$rez = $this->DB->QUR_SEL($sql);
//echo $sql.'<pre>'.print_r($rez,1).'</pre>';
//$out[] = $sql;
//$out[] = $rez;
if(!$rez['err']&&$rez['kol']){
foreach ($rez['rez'] as $k => $v){
$out[] = $v;
}
}else{//Возможно не указали препода!
$sql = 'SELECT up.id,up.data_c,up.descrip,up.status FROM '.$this->TUchebplansPrepod.' as up WHERE up.id_uchebplans='.$id_uchebplans.' ORDER BY up.data_c DESC';
$rez = $this->DB->QUR_SEL($sql);
if(!$rez['err']&&$rez['kol']){
foreach ($rez['rez'] as $k => $v){
$v['fio'] = 'Не указан';
$out[] = $v;
}
}
}
//}
return $out;
}
}