DB = $DB; $this->TFile = $ST['dbpf'].'_fshp_file'; $this->TFiles = $ST['dbpf'].'_fshp_files'; $this->TUchebplans = $ST['dbpf'].'_fshp_uchebplans'; $this->TUchebplans_compet = $ST['dbpf'].'_fshp_uchebplans_compet'; $this->TCompet = $ST['dbpf'].'_fshp_compet'; } public function HTML(){ GLOBAL $WorkDIR,$ST,$DB; $CHPU = new class_CHPU($WorkDIR); $URLS = $CHPU->uri(); $smartyC = new class_smarty(); $smarty = $smartyC->config(__DIR__.'\..\tpl'); $view = 'all'; $out = array('name'=>'Шахтинские планы редактор','body'=>''); if(isset($_POST['sd_btn_confirm'])) {//поиск дисциплины и внесение изменений! $json=array(); //Создадим новые json для дисциплин foreach($_POST['discip'] as $id => $v){ $_POST['discip'][$id]['json'] = json_decode(urldecode($v['json']),1); foreach($_POST['discip'][$id]['json'] as $kurs => $sems){ foreach($sems as $sem => $params){ foreach($params as $param => $value){ if(is_array($value)){ if(isset($value['new'])) $json[$id][$kurs][$sem][$param] = $value['new']; else $json[$id][$kurs][$sem][$param] = $value['old']; }else{ $json[$id][$kurs][$sem][$param] = $value; } } } } } if(isset($json)&&count($json)){ foreach($json as $id => $v){ $sql = 'UPDATE '.$this->TUchebplans.' SET json="'.$this->DB->rescape(json_encode($v,JSON_UNESCAPED_UNICODE)).'" WHERE id='.$id.' LIMIT 1'; $this->DB->QUR($sql); } } //echo '
'.print_r($json,1).'
'; //echo '
'.print_r($_POST,1).'
'; //exit(); } if(isset($_POST['sd_btn'])) {//поиск дисциплины и внесение изменений! //echo '
'.print_r($_POST,1).'
'; $discip = array(); $sem_sel = array(); if(is_array($_POST['sd_seme'])) $sem_sel = $_POST['sd_seme']; else { //if($_POST['sd_seme']==0) $_POST['sd_seme']=1;//TODO убрать! $sem_sel = array($_POST['sd_seme']); } $_POST['sd_seme'] = $sem_sel; foreach($_POST['discip'] as $k => $v){ if(isset($v['sel'])){ $v['json'] = json_decode(urldecode($v['json']),1); foreach ($v['json'] as $kurs => $sems) { foreach ($sems as $sem => $params) { if(in_array($sem,$sem_sel)){//наш семестр //обходим все выставленные условия foreach($_POST['sd'] as $param => $dan){ if(isset($params[$param])){ if($dan['usl']!='null'){ $zamena =array(); if($dan['usl']=='replace'){ $zamena['old'] = $params[$param]; $zamena['new'] = $dan['newznach']; } if($dan['usl']=='ifequal'){ $zamena['old'] = $params[$param]; if($params[$param]==$dan['oldznach']){ $zamena['new'] = $dan['newznach']; }else{ $zamena['new'] = $params[$param]; } } if($dan['usl']=='ifmore'){ $zamena['old'] = $params[$param]; if($params[$param]>$dan['oldznach']){ $zamena['new'] = $dan['newznach']; }else{ $zamena['new'] = $params[$param]; } } if($dan['usl']=='ifmoree'){ $zamena['old'] = $params[$param]; if($params[$param]>=$dan['oldznach']){ $zamena['new'] = $dan['newznach']; }else{ $zamena['new'] = $params[$param]; } } if($dan['usl']=='ifless'){ $zamena['old'] = $params[$param]; if($params[$param]<$dan['oldznach']){ $zamena['new'] = $dan['newznach']; }else{ $zamena['new'] = $params[$param]; } } if($dan['usl']=='iflesse'){ $zamena['old'] = $params[$param]; if($params[$param]<=$dan['oldznach']){ $zamena['new'] = $dan['newznach']; }else{ $zamena['new'] = $params[$param]; } } if($dan['usl']=='insert'){ $zamena['old'] = $params[$param]; $zamena['new'] = $dan['newznach']; } $v['json'][$kurs][$sem][$param] = $zamena; } }else{ if($dan['usl']=='insert'){ $zamena =array(); $zamena['old'] = 0; $zamena['new'] = $dan['newznach']; $v['json'][$kurs][$sem][$param] = $zamena; } } } } } } $discip[] = $v; } } $_POST['discip'] = $discip; $smarty->assign('post',$_POST); $view = 'search_discip_confirm'; } if(isset($_POST['search_discip_btn'])) {//поиск дисциплины $search_discip = $_POST['search_discip']; $discips = $this->discip_search($search_discip); $smarty->assign('discips',$discips['items']); $smarty->assign('jsons',$discips['jsons']); $smarty->assign('search_discip',$search_discip); $view = 'search_discip'; } if(isset($_POST['sel_btn'])){//отображение дисциплин по кафедре $kaf_el = explode('##',$_POST['kaf_el']); $discips = $this->discip_gets($kaf_el[1]); $smarty->assign('kafedra',$kaf_el); $smarty->assign('discips',$discips); $view = 'discips'; } if(isset($_POST['union_btn_end'])){ $kaf_old_name = $this->DB->rescape($_POST['kaf_old_name']); $kaf_new_name = $this->DB->rescape($_POST['kaf_new_name']); if($kaf_new_name!='') { $sql = 'UPDATE ' . $this->TUchebplans . ' as u,' . $this->TFile . ' as f SET u.kaf_name="' . $kaf_new_name . '" WHERE u.kaf_name="' . $kaf_old_name . '" AND f.god_nach_podgot=' . $_SESSION['year_cur'] . ''; $rez = $this->DB->QUR($sql); } } if(isset($_POST['union_btn'])){ $kaf_old = explode('##',$_POST['kaf_old']); $kaf_new = explode('##',$_POST['kaf_new']); $view = 'union'; $smarty->assign('kaf_old',$kaf_old); $smarty->assign('kaf_new',$kaf_new); } $smarty->assign('kafedras',$this->kafedra_gets()); $smarty->assign('view',$view); $out['body'] = $smarty->fetch('page_shahtplan_pravka.html'); return $out; } /** * Получение всех кафедр из учебных планов * @return array */ function kafedra_gets(){ $out = array(); $sql = 'SELECT u.kaf_kod,u.kaf_name FROM '.$this->TUchebplans.' as u, '.$this->TFile.' as f WHERE u.kaf_kod!="" AND f.id_file=u.id_file AND f.god_nach_podgot='.$_SESSION['year_cur'].' GROUP BY u.kaf_name ORDER BY u.kaf_kod,u.kaf_name'; $rez = $this->DB->QUR_SEL($sql); if(!$rez['err']&&$rez['kol']){ foreach ($rez['rez'] as $k => $v){ $out[] = $v; } } return $out; } function discip_gets($kaf_name){ $out = array(); $sql = 'SELECT u.id,u.index1,u.name,u.id_file,u.ekzamen,u.zachet,u.zachetsocenk,u.kr,u.kp,u.kontrol,u.json FROM '.$this->TUchebplans.' as u, '.$this->TFile.' as f WHERE ( u.name != "Форма контроля" ) AND u.kaf_name!="'.$this->DB->rescape($kaf_name).'" AND f.id_file=u.id_file AND f.god_nach_podgot='.$_SESSION['year_cur'].' ORDER BY u.kaf_kod,u.kaf_name'; $rez = $this->DB->QUR_SEL($sql); if(!$rez['err']&&$rez['kol']){ foreach ($rez['rez'] as $k => $v){ $v['json'] = json_decode($v['json'],1); $out[] = $v; } } return $out; } /** * Поиск дисциплины * @param $discip_name * @return array */ function discip_search($discip_name){ $out = array(); $sql = 'SELECT u.id,u.index1,u.name,u.id_file,u.ekzamen,u.zachet,u.zachetsocenk,u.kr,u.kp,u.kontrol,u.json,f.kafedra,f.fo FROM '.$this->TUchebplans.' as u, '.$this->TFile.' as f WHERE ( u.name != "Форма контроля" ) AND u.name="'.$this->DB->rescape($discip_name).'" AND f.id_file=u.id_file AND f.god_nach_podgot='.$_SESSION['year_cur'].' ORDER BY u.kaf_kod,u.kaf_name'; $rez = $this->DB->QUR_SEL($sql); //echo $sql.'
'.print_r($rez,1).'
'; //SELECT u.id,u.index1,u.name,u.id_file,u.ekzamen,u.zachet,u.zachetsocenk,u.kr,u.kp,u.kontrol,u.json FROM acs_fshp_uchebplans as u, acs_fshp_file as f WHERE ( u.name != "Форма контроля" ) AND u.name="История" AND f.id_file=u.id_file AND f.god_nach_podgot=2023 ORDER BY u.kaf_kod,u.kaf_name $jsons = array(); if(!$rez['err']&&$rez['kol']){ foreach ($rez['rez'] as $k => $v){ $v['json'] = json_decode($v['json'],1); if(count($v['json'])) { foreach($v['json'] as $kurs => $json1){ foreach($json1 as $sem => $json2){ if(count($json2)) $jsons = array_merge($jsons,$json2); } } //{ // "2": // { // "3": {"pr":4,"sr":"64","krat":"0.25","kontrol":"3.75","ze":"2"} // } //} } $out[] = $v; } } $jsons = array_unique($jsons); return array('items'=>$out,'jsons'=>$jsons); } }