DB = $DB; if(isset($data['cron'])&&$data['cron']==1){ }else { $CHPU = new class_CHPU($WorkDIR); $this->URLS = $CHPU->uri(); } if(isset($data['fakultet'])) $this->fakultet = $data['fakultet']; if(isset($data['kafedra'])) $this->kafedra = $data['kafedra']; //echo '
'.print_r($data,1).'
';exit(); $this->tip = 'prorektor'; if(isset($data['tip'])) $this->tip = $data['tip']; $this->TFile = $ST['dbpf'].'_fshp_file'; $this->TUchebplans = $ST['dbpf'].'_fshp_uchebplans'; } public function HTML(){ GLOBAL $WorkDIR; $out = array(); $smartyC = new class_smarty(); $smarty = $smartyC->config(__DIR__.'\..\tpl'); $urls = $this->URLS; //echo '
'.print_r($urls,1).'
';Array([0]=statpur [1]=pdf01) if(isset($urls[1])){ if($urls[1]=='pdf01'&&isset($urls[2])){ $id_fak = (int)$urls[2]; if($this->tip=='prorektor') { $data = $this->get_facultets($id_fak); } if($this->tip=='dekan') { $data = $this->get_facultets($this->get_facultet_by_name($this->fakultet)); } if($this->tip=='zavkaf') { $facultets = $this->get_facultets($this->get_facultet_by_name($this->fakultet)); foreach ($facultets as $key1 => $schools){ foreach ($schools as $key2 => $school){ foreach ($school['kafedras'] as $key3 => $kafedra){ if($kafedra['name']!=$this->kafedra){ unset($facultets[$key1][$key2]['kafedras'][$key3]); } } } } $data = $facultets; //echo '
'.print_r($data,1).'
'; exit(); } $smarty->assign('TPL',$WorkDIR); $smarty->assign('facultets', $data); $smarty->display('page_statpur_pdf.html'); exit(); } }else { $des='view'; if(isset($_POST['fio_search'])){ $des='search'; $fio = $this->DB->rescape($_POST['fio']); $itogs=array(); $itogsPrep=array(); $itogsPrep2=array(); $sql = 'SELECT id,fio FROM acs_users WHERE fio LIKE "%'.$fio.'%"'; $rez = $this->DB->QUR_SEL($sql); if(!$rez['err']&&$rez['kol']){ foreach($rez['rez'] as $key => $val){ $sql1 = 'SELECT dp.id_uchebplans,up.id,up.index1,up.name,up.kaf_kod,up.kaf_name FROM acs_fshp_disciplin_prepod as dp, acs_fshp_uchebplans as up WHERE dp.id_prepod = '.$val['id'].' AND up.id=dp.id_uchebplans'; $rez1 = $this->DB->QUR_SEL($sql1); //echo '
'.print_r($rez1,1).'
';exit(); if(!$rez1['err']&&$rez1['kol']) { foreach ($rez1['rez'] as $key1 => $val1) { $itog['kaf_kod'] = $val1['kaf_kod']; $itog['kaf_name'] = $val1['kaf_name']; $itog['index1'] = $val1['index1']; $itog['name'] = $val1['name']; $itog['save'] = array(); $sql2 = 'SELECT sv.* FROM acs_fshp_rpd_save as sv WHERE sv.id_discip='.$val1['id']; $rez2 = $this->DB->QUR_SEL($sql2); //echo '
'.print_r($rez2,1).'
';//exit(); if(!$rez2['err']&&$rez2['kol']){ foreach($rez2['rez'] as $key2 => $val2){ $rpdsave=array(); $rpdsave[] = $val2; $itog['save'] = $this->save_calcul($rpdsave); $itogsPrep[$val['fio']][]=round($itog['save']['proc']/100,2); } }else{ $itogsPrep[$val['fio']][]=0; } $itogs[$val['fio']][]=$itog; $itogsPrep2[$val['fio']]['all'] = count($itogsPrep[$val['fio']]); $sums = 0; foreach($itogsPrep[$val['fio']] as $k => $v) $sums+=$v; $itogsPrep2[$val['fio']]['proc'] = round(($sums/count($itogsPrep[$val['fio']]))*100,2); } } } } $smarty->assign('itogs', $itogs); $smarty->assign('itogsPrep2', $itogsPrep2); }else { if ($this->tip == 'prorektor') { $out = array('name' => 'Статистика проректора', 'body' => ''); $smarty->assign('facultets', $this->get_facultets()); } if ($this->tip == 'dekan') { $out = array('name' => 'Статистика "' . $this->fakultet . '"', 'body' => ''); $smarty->assign('facultets', $this->get_facultets($this->get_facultet_by_name($this->fakultet))); } if ($this->tip == 'zavkaf') { $out = array('name' => 'Статистика "' . $this->kafedra . '"', 'body' => ''); $facultets = $this->get_facultets($this->get_facultet_by_name($this->fakultet)); /*Array([tip] => zavkaf[fakultet] => Факультет экономики и управления[kafedra] => Маркетинга, сервиса и туризма)*/ //echo '
'.print_r($facultets,1).'
'; exit(); foreach ($facultets as $key1 => $schools) { foreach ($schools as $key2 => $school) { foreach ($school['kafedras'] as $key3 => $kafedra) { if ($kafedra['name'] != $this->kafedra) { unset($facultets[$key1][$key2]['kafedras'][$key3]); } } } } $smarty->assign('facultets', $facultets); $otherRPD = $this->get_other_naznach($this->kafedra); $smarty->assign('otherRPD', $otherRPD); } $smarty->assign('fakultet', $this->fakultet); $smarty->assign('kafedra', $this->kafedra); $smarty->assign('tip', $this->tip); } $smarty->assign('des', $des); $out['body'] = $smarty->fetch('page_statpur.html'); //$out['body'] .= '
'.print_r($_SESSION,1).'
'.'----------------'.$this->fakultet; } return $out; } /** * Получение назначений на РПД для не своей кафедры, зав.кафы могут назначать и другим кафедрам! * @param $kafname * @return array */ function get_other_naznach($kafname){ $sql = 'SELECT up.id,up.index1,up.name, t.kafedra FROM '.$this->TUchebplans.' as up, '.$this->TFile.' as t WHERE up.kaf_name="'.$kafname.'" AND t.kafedra != "'.$kafname.'" AND up.id_file=t.id_file ORDER BY t.shifr,t.god_nach_podgot,t.fo'; $rez = $this->DB->QUR_SEL($sql); //echo $sql.'
'.print_r($rez,1).'
'; exit(); if(!$rez['err']&&$rez['kol']){ foreach($rez['rez'] as $key => $val){ $prepods = $this->get_statUchebPlanDiscipsPrepod($val['id']); if(count($prepods)) { $val['prepods'] = $this->get_statUchebPlanDiscipsPrepod($val['id']); $out[] = $val; } } } //echo $sql.'
'.print_r($out,1).'
'; exit(); return $out; } function get_facultet_by_name($name){ $out = 0; $sql = 'SELECT id FROM acs_faculties WHERE name="'.$this->fakultet.'"'; $rez = $this->DB->QUR_SEL($sql); if(!$rez['err']&&$rez['kol']){ $out = $rez['rez'][0]['id']; } return $out; } function get_facultets($id_fak=0){ $out = array(); if($id_fak==0) { $sql = 'SELECT school.name as school_name, facultie.id as facultie_id, facultie.name as facultie_name FROM acs_schools as school, acs_faculties as facultie WHERE school.id=facultie.id_school ORDER BY school.name,facultie.name'; }else{ $sql = 'SELECT school.name as school_name, facultie.id as facultie_id, facultie.name as facultie_name FROM acs_schools as school, acs_faculties as facultie WHERE school.id=facultie.id_school AND facultie.id='.$id_fak.' ORDER BY school.name,facultie.name'; } $rez = $this->DB->QUR_SEL($sql); //echo $sql.'
'.print_r($rez,1).'
';exit(); if(!$rez['err']&&$rez['kol']){ foreach($rez['rez'] as $key => $val){ $val['kafedras'] = $this->get_kafedras($val['facultie_id']); $out[$val['school_name']][] = $val; } } //echo $sql.'
'.print_r($rez,1).print_r($out,1).'
';exit(); return $out; } function get_kafedras($id_fakultet){ $out = array(); $cache = $this->cache_check('kafedras',$id_fakultet); if(count($cache)){ $out = $cache; }else { $sql = 'SELECT id,name,code FROM acs_kafedres WHERE id_facult = ' . $id_fakultet . ' ORDER BY code,name'; $rez = $this->DB->QUR_SEL($sql); //echo $sql.'
'.print_r($rez,1).'
'; if (!$rez['err'] && $rez['kol']) { foreach ($rez['rez'] as $key => $val) { $tmp['id'] = $val['id']; $tmp['name'] = $val['name']; $tmp['code'] = $val['code']; $tmp['up'] = $this->get_statUchebPlan($tmp['name']); $out[] = $tmp; } $this->cache_check('kafedras',$id_fakultet,$out); } } return $out; } function get_statUchebPlan($kafedra){ $out = array(); if($kafedra=='Кафедра госпитальной хирургии и последипломного образования') $kafedra = 'Госпитальной хирургии и последипломного образования'; if($kafedra=='Кафедра госпитальной терапии и последипломного образования') $kafedra = 'Госпитальной терапии и последипломного образования'; $cache = $this->cache_check('statUchebPlan',$kafedra); if(count($cache)){ $out = $cache; }else { $sql = 'SELECT id,data_c,id_file,program,shifr,naprav,profil,kvalif,god_nach_podgot,fo,srok_poluch_obr FROM acs_fshp_file WHERE kafedra = "' . $kafedra . '" AND god_nach_podgot='.$_SESSION['year_cur'].' ORDER BY naprav'; $rez = $this->DB->QUR_SEL($sql); //echo $sql.'
'.print_r($rez,1).'
'; //exit(); if (!$rez['err'] && $rez['kol']) { foreach ($rez['rez'] as $key => $val) { $val['discips'] = $this->get_statUchebPlanDiscips($val['id_file']); $out[] = $val; } $this->cache_check('statUchebPlan',$kafedra,$out); } } return $out; } function get_statUchebPlanDiscips($id_file){ $out = array(); $cache = $this->cache_check('statUchebPlanDiscips',$id_file); if(count($cache)){ $out = $cache; }else { $sql = 'SELECT id,index1,name FROM acs_fshp_uchebplans WHERE id_file = ' . $id_file . ' ORDER BY index1'; //echo $sql.'
'; $rez = $this->DB->QUR_SEL($sql); if (!$rez['err'] && $rez['kol']) { foreach ($rez['rez'] as $key => $val) { $prepods = $this->get_statUchebPlanDiscipsPrepod($val['id']); //echo '
'.print_r($prepods,1).'
'; if (count($prepods)) { $val['prepods'] = $prepods;//$this->get_statUchebPlanDiscipsPrepod($val['id']); $out[] = $val; } } $this->cache_check('statUchebPlanDiscips',$id_file,$out); } } //echo 'get_statUchebPlanDiscips:
'.print_r($out,1).'
'; return $out; } /** * Кэширование SQL запросов * @param $sql1 * @param $key * @return array|mixed|null */ function cache_sess($sql1,$key='StatPUR_Cache',$des='add'){ if($des=='del'){ if(isset($_SESSION[$key][md5($sql1)])) unset($_SESSION[$key][md5($sql1)]); }else { if (!isset($_SESSION[$key][md5($sql1)])) { $rez1 = $this->DB->QUR_SEL($sql1); $_SESSION[$key][md5($sql1)] = $rez1; } else { $rez1 = $_SESSION[$key][md5($sql1)]; } } return $rez1; } function get_statUchebPlanDiscipsPrepod($id_uchebplan){ $out = array(); $cache = $this->cache_check('statUchebPlanDiscipsPrepod',$id_uchebplan); if(count($cache)){ $out = $cache; }else { $sql = 'SELECT u.id,u.fio,fdp.data_c,fdp.descrip,fdp.status FROM acs_fshp_disciplin_prepod as fdp, acs_users as u WHERE fdp.id_uchebplans = ' . $id_uchebplan . ' AND u.id=fdp.id_prepod'; //echo $sql.'
'; //$rez = $this->DB->QUR_SEL($sql); $rez = $this->cache_sess($sql); if (!$rez['err'] && $rez['kol']) { foreach ($rez['rez'] as $key => $val) { $val['saves'] = $this->get_statUchebPlanDiscipsSaves($id_uchebplan, $val['id']); $out[] = $val; } $this->cache_check('statUchebPlanDiscipsPrepod',$id_uchebplan,$out); } } return $out; } function get_statUchebPlanDiscipsSaves($id_discip,$id_prepod){ $out = array(); $cache = $this->cache_check('statUchebPlanDiscipsSaves',$id_discip.'_'.$id_prepod); if(count($cache)){ $out = $cache; }else { $sql = 'SELECT * FROM acs_fshp_rpd_save WHERE id_discip = ' . $id_discip . ' AND id_prepod = ' . $id_prepod . ' ORDER BY data_c'; //echo $sql.'
'; $rez = $this->DB->QUR_SEL($sql); $all_save = 16; $out = array('all' => $all_save, 'kol_save' => 0, 'proc' => 0); if (!$rez['err'] && $rez['kol']) { $out = $this->save_calcul($rez['rez']); //foreach ($rez['rez'] as $key => $val) { // $kol_save = 0; // if (trim($val['razdel1']) !== '') $kol_save++; // if (trim($val['razdel2']) !== '') $kol_save++; // if (trim($val['razdel3']) !== '') $kol_save++; // if (trim($val['razdel4']) !== '') $kol_save++; // if (trim($val['razdel5']) !== '') $kol_save++; // if (trim($val['razdel5_4']) !== '') $kol_save++; // if (trim($val['razdel5_5']) !== '') $kol_save++; // if (trim($val['razdel5_6']) !== '') $kol_save++; // if (trim($val['razdel5_7']) !== '') $kol_save++; // if (trim($val['razdel5_8']) !== '') $kol_save++; // if (trim($val['razdel5_9']) !== '') $kol_save++; // if (trim($val['razdel6_1']) !== '') $kol_save++; // if (trim($val['razdel6_2']) !== '') $kol_save++; // if (trim($val['razdel7']) !== '') $kol_save++; // if (trim($val['razdel7_2']) !== '') $kol_save++; // if (trim($val['razdel7_3']) !== '') $kol_save++; // $out = array('all' => $all_save, 'kol_save' => $kol_save, 'proc' => round((($kol_save / $all_save) * 100), 2)); //} $this->cache_check('statUchebPlanDiscipsSaves',$id_discip.'_'.$id_prepod,$out); } } return $out; } /** * Подсчет сохранений * @param $save * @return array */ function save_calcul($save){ $all_save = 16; $nullvals = array('{"0":[{"sem":"null"}]}','null'); foreach ($save as $key => $val) { $kol_save = 0; if (trim($val['razdel1']) !== '') { if (!in_array($val['razdel1'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel2']) !== '') { if (!in_array($val['razdel2'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel3']) !== '') { if (!in_array($val['razdel3'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel4']) !== '') { if (!in_array($val['razdel4'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel5']) !== '') { if (!in_array($val['razdel5'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel5_4']) !== '') { if (!in_array($val['razdel5_4'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel5_5']) !== '') { if (!in_array($val['razdel5_5'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel5_6']) !== '') { if (!in_array($val['razdel5_6'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel5_7']) !== '') { if (!in_array($val['razdel5_7'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel5_8']) !== '') { if (!in_array($val['razdel5_8'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel5_9']) !== '') { if (!in_array($val['razdel5_9'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel6_1']) !== '') { if (!in_array($val['razdel6_1'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel6_2']) !== '') { if (!in_array($val['razdel6_2'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel7']) !== '') { if (!in_array($val['razdel7'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel7_2']) !== '') { if (!in_array($val['razdel7_2'], $nullvals)) $kol_save++; else $all_save--; } if (trim($val['razdel7_3']) !== '') { if (!in_array($val['razdel7_3'], $nullvals)) $kol_save++; else $all_save--; } } $out = array('all' => $all_save, 'kol_save' => $kol_save, 'proc' => round((($kol_save / $all_save) * 100), 2)); return $out; } /** * Проверка кэша для $what и его параметров $param * если передали массив $data то сохраняем данные в кэш * @param $what * @param $param * @param $data * @return array|mixed */ function cache_check($what,$param,$data=array()){ $dir = 'tmp/statrpd/'; if(!file_exists($dir)) mkdir($dir,0777,1); $file = $dir.$what.'_'.$_SESSION['year_cur'].'_'.$param.'.json'; if(count($data)){//создадим файл кэша file_put_contents($file,json_encode($data)); $arr = $data; }else {//получим данные файла кэша if (file_exists($file)) { $times = 60*60*24; // 3 часа if($what=='statUchebPlanDiscipsSaves') $times = 60*60*12; // 1 час if((filectime($file)+$times)>=time()){//если файл изменился в течении последних 3 часов $arr = json_decode(file_get_contents($file), 1); }else{ $arr = array(); } } else { $arr = array(); } } return $arr; } function prepods_get($fakultet,$kafedra){ $out = array(); //$sql = 'SELECT id,data_c,data_u,id_user,zvanie,dolgnost,stepen FROM acs_teachers WHERE fakultet="'.$fakultet.'" AND kafedra="'.$kafedra.'"'; $sql = 'SELECT t.id,t.id_user,t.zvanie,t.dolgnost,t.stepen,u.data_c,u.data_u,u.fio FROM acs_teachers as t, acs_users as u WHERE t.fakultet="'.$fakultet.'" AND t.kafedra="'.$kafedra.'" AND t.id_user=u.id ORDER BY u.fio'; $rez = $this->DB->QUR_SEL($sql); if(!$rez['err']&&$rez['kol']){ $out = $rez['rez']; } return $out; } }