EIOS/inc/instr.php

515 lines
20 KiB
PHP
Raw Normal View History

2023-12-28 15:39:22 +03:00
<?php
if (isset($_GET['page'])){ //РЕДАКТИРОВАНИЕ ИНСТРУКЦИЙ
if($_GET['page']=='write'){
//НАСТРОИМ ПАПКУ ДЛЯ ЗАГРУЗКИ ФОТО
$_SESSION['niceditor']['path1']='../../upload/instruction/'.$_SESSION['user']['id'].'';
$_SESSION['niceditor']['path2']='/upload/instruction/'.$_SESSION['user']['id'].'';
//echo '<pre>'.print_r($_SESSION['niceditor'],1).'</pre>';
if (!file_exists($_SESSION['niceditor']['path1'])){
//echo '1';
mkdir($_SESSION['niceditor']['path1'], 0766);
}
if (!file_exists('./upload/instruction/'.$_SESSION['user']['id'].'')){
//echo '2';
mkdir('./upload/instruction/'.$_SESSION['user']['id'], 0766);
}
if (isset($_POST['save_help'])){//СОХРАНЕНИЕ ЗАПИСИ
$id = (int)$_POST['id'];
$id_category = (int)$_POST['id_category'];
$title = get_data_fu($_POST['title']);
$text_f = addslashes($_POST['text_f']);
//$id_user = $_SESSION['user']['id'];
if (isset($_POST['status'])) $status=1; else $status=0;
$sql = 'INSERT INTO '.$ST['dbpf'].'_help VALUES (0,'.mktime().','.mktime().','.$id_category.',"'.$title.'","'.$text_f.'",'.$status.', 0)';
/*echo $sql;
exit;*/
$rez=$DB->QUR_SEL($sql);
if(!$rez['err']){
$form['msg']='Запись добавлена';
unset($_GET['des']);
}else{
$form['err'][]='Ошибка добавления данных!';
}
}
if (isset($_POST['help_edit'])){//РЕДАКТИРОВАНИЕ ЗАПИСИ
$id = (int)$_POST['id'];
$id_category = (int)$_POST['id_category'];
$title = get_data_fu($_POST['title']);
$text_f = addslashes($_POST['text_f']);
$id_user = $_SESSION['user']['id'];
if (isset($_POST['status'])) $status=1; else $status=0;
if (isset($_POST['zakrep'])) $zakrep=1; else $zakrep=0;
//$sql = 'UPDATE '.$ST['dbpf'].'_blogs SET data_u='.mktime().',id_category='.$id_category.',id_user='.$id_user.',title="'.$title.'",text_f="'.$text_f.'",comment='.$comment.', zakrep='.$zakrep.' WHERE id='.$id.' AND id_user='.$_SESSION['user']['id'].'';
$sql = 'UPDATE '.$ST['dbpf'].'_help SET data_u='.mktime().',id_category='.$id_category.',title="'.$title.'",text_f="'.$text_f.'",status="'.$status.'" WHERE id='.$id.'';
//echo $sql;
$rez=$DB->QUR_SEL($sql);
if(!$rez['err']){
$form['msg']='Запись изменена';
unset($_GET['des']);
}else{
$form['err'][]='Ошибка изменения данных!';
}
}
if (isset($_GET['des'])){//ОБРАБОТКА ДЕЙСТВИЙ не требующих ответа от пользователя
if($_GET['des']=='del'){//Удаление блога
$form['id']=(int)$_GET['id'];
$sql='SELECT * FROM '.$ST['dbpf'].'_blogs WHERE id='.$form['id'].'';
$rez=$DB->QUR_SEL($sql);
if($rez){
if ($rez[1]['id_user']==$_SESSION['user']['id']){//Хозяин записи
if($rez[1]['status']==1)
$DB->QUR('UPDATE '.$ST['dbpf'].'_blogs SET status=0 WHERE id='.$form['id'].' LIMIT 1');
if($rez[1]['status']==0)
$DB->QUR('DELETE FROM '.$ST['dbpf'].'_blogs WHERE id='.$form['id'].' LIMIT 1');
}else{
$DB->QUR('UPDATE '.$ST['dbpf'].'_blogs SET status=0 WHERE id='.$form['id'].' LIMIT 1');
}
}
unset($_GET['des']);
}
if($_GET['des']=='aprove'){//Активация блога
$form['id']=(int)$_GET['id'];
$DB->QUR('UPDATE '.$ST['dbpf'].'_blogs SET status=1 WHERE id='.$form['id'].' LIMIT 1');
unset($_GET['des']);
}
}
if (isset($_GET['des'])){//ОБРАБОТКА ДЕЙСТВИЙ
if ($_GET['des']=='add'){//ФОРМА ДОБАВЛЕНИЯ
$regim='aded';
$blogs=array();//
$form=array();
$form['ftitle']=$ST['page']['name'] = 'Добавление записи';
$form['btn_url']='save_help';
$form['btn_name']='Добавить запись';
$form['id']=0;
/*$sql1='SELECT * FROM '.$ST['dbpf'].'_blogs_category ORDER BY pos';
$rez1=$DB->QUR_SEL($sql1);
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
if (in_array($val1['id'],$_SESSION['user']['blog']['id_blog_category'])){
$form['categorys'][]=$val1;
}
}
}*/
$sql1='SELECT * FROM '.$ST['dbpf'].'_help_category ';
$rez1=$DB->QUR_SEL($sql1);
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
//if (in_array($val1['id'],$_SESSION['user']['blog']['id_blog_category'])){
$form['categorys'][]=$val1;
//}
}
}
}
if ($_GET['des']=='edit'){//ФОРМА РЕДАТКИРОВАНИЯ
$regim='aded';
$blogs=array();//
$form=array();
$form['ftitle']=$ST['page']['name'] = 'Редактирование записи';
$form['btn_url']='help_edit';
$form['btn_name']='Редактировать запись';
$form['id']=(int)$_GET['id'];
//$sql='SELECT * FROM '.$ST['dbpf'].'_blogs WHERE id='.$form['id'].' AND id_user='.$_SESSION['user']['id'].'';
$sql='SELECT * FROM '.$ST['dbpf'].'_help WHERE id='.$form['id'].'';
$rez=$DB->QUR_SEL($sql);
if($rez){
$form['title']=out_data_fu($rez[1]['title']);
$form['text_f']=out_data_fu($rez[1]['text_f']);
$form['comment']=(int)$rez[1]['comment'];
$form['zakrep']=(int)$rez[1]['zakrep'];
//**************старое
$sql1='SELECT * FROM '.$ST['dbpf'].'_blogs_category ORDER BY pos';
$rez1=$DB->QUR_SEL($sql1);
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
if (in_array($val1['id'],$_SESSION['user']['blog']['id_blog_category'])){
if($val1['id']==$rez[1]['id_category']) $val1['sel']=1;
$form['categorys'][]=$val1;
}
}
}
//новое
$sql1='SELECT * FROM '.$ST['dbpf'].'_help_category ';
$rez1=$DB->QUR_SEL($sql1);
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
//if (in_array($val1['id'],$_SESSION['user']['blog']['id_blog_category'])){
$form['categorys'][]=$val1;
//}
}
}
}
}
}else{
$regim='show'; $form=array(); $blogs=array();
//надо определить записи которые необходимо отобразить пользователю!!!
$id_user = $_SESSION['user']['id'];
$id_cat = $_SESSION['user']['blog']['id_blog_category']; $id_cats=array();
foreach($id_cat as $key => $val) $id_cats[]=$val;
if (count($id_cats)) $wh = ' OR (id_category='.implode(' OR id_category=',$id_cats).')';
else $wh='';
//$pagi=pagination_blog('SELECT * FROM '.$ST['dbpf'].'_blogs WHERE id_user='.$id_user.$wh.'',10);
$pagi=pagination_blog('SELECT * FROM '.$ST['dbpf'].'_help ',10);
$sql1='SELECT * FROM '.$ST['dbpf'].'_help ORDER BY data_c DESC '.$pagi['limit'];
$rez1=$DB->QUR_SEL($sql1); //echo $sql1;
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
$val1['data_c']=date('H:i:s d.m.Y',$val1['data_c']);
$val1['data_u']=date('H:i:s d.m.Y',$val1['data_u']);
$val1['title']=out_data_fu($val1['title']);
$rez=$DB->QUR_SEL('SELECT * FROM '.$ST['dbpf'].'_blogs_category WHERE id='.$val1['id_category'].' LIMIT 1');
if($rez){ $val1['category'] = $rez[1]['name']; } else $val1['category']='не определили';
$blogs[] = $val1;
}
}
$ST['page']['name'] = 'Просмотр блогов';
}
$smarty->assign('form',$form);
$smarty->assign('regim',$regim);
$smarty->assign('pagination',$pagi);
$smarty->assign('blogs',$blogs);//список записей в блоге
$maincontent = $smarty->fetch('tpl_instruction_write.html');
}
elseif($_GET['page']=='razdel'){ //ИНСТРУКЦИИ РАЗДЕЛЫ
$msg = 0; //нет сообщений
//добавление нового раздела
if (isset($_POST['add_category'])){
$name = addslashes($_POST['name']);
$id_main = addslashes($_POST['id_main']);
$sql = 'INSERT INTO '.$ST['dbpf'].'_help_category VALUES (0,"'.$name.'",'.$id_main.', 0)';
$rez=$DB->QUR_SEL($sql);
$msg = 1;
}
//все категории
$categoryAll = array();
$sql = 'SELECT * FROM '.$ST['dbpf'].'_help_category ';
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach ($rez as $key => $val) if($key){
$sql_razdel = 'SELECT * FROM '.$ST['dbpf'].'_help_category WHERE id = "'.$val['id_main'].'" ';
$rez_razdel = $DB->QUR_SEL($sql_razdel);
$val['razdel'] = $rez_razdel[1]['name'];
$categoryAll[] = $val;
}
}
/*****/
$smarty->assign('categoryAll',$categoryAll);
$smarty->assign('msg',$msg);
$maincontent = $smarty->fetch('tpl_instruction_razdel.html');
}
}
else{//ПРОСМОТР БЛОГА
$blog=array();
$ST['page']['name'] = 'Инструкции';
$blog['breadcrumb']=array();//навигационная лента
$blog['breadcrumb'][0]['url']='/';
$blog['breadcrumb'][0]['name']='Главная';
$blog['breadcrumb'][1]['url']='/help/';
$blog['breadcrumb'][1]['name']='Инструкции';
$blog['breadcrumb'][1]['active']=1;
{//КАТЕГОРИЯ
$icons=array(0=>'icon-trophy','icon-plane','icon-pushpin','icon-beaker','icon-bullhorn','icon-trophy','icon-umbrella');
$blog['category']=array();
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs_category ORDER BY pos LIMIT 6';
$rez=$DB->QUR_SEL($sql);
if($rez){
$i=0; foreach($rez as $key => $val)if($key){
$blog['category'][$i]['url']='/blog/'.$val['alt_name'].'/';
$blog['category'][$i]['name']=''.out_data_fu($val['name']).'';
$blog['category'][$i]['icon']=$icons[$i];
$i++;
}
}
}
{//ПОСЛЕДНИЕ СООБЩЕНИЯ
$blog['latest']=array();
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs ORDER BY zakrep, data_c DESC LIMIT 5';
$rez=$DB->QUR_SEL($sql);
if($rez){
$i=0; foreach($rez as $key => $val)if($key){
$blog['latest'][$i]['date']=date('H:i:s d.m.Y',$val['data_u']);
$blog['latest'][$i]['url']='/blog/'.$val['id'].'/';
$t=img_get_all(out_data_fu($val['text_f']));
$blog['latest'][$i]['img']=$t[0];
$blog['latest'][$i]['text_s']=strip_tags(out_data_fu($val['text_f']));
$i++;
}
}
}
$mes=array('01'=>'Январь','02'=>'Февраль','03'=>'Март','04'=>'Апрель','05'=>'Май','06'=>'Июнь','07'=>'Июль','08'=>'Август','09'=>'Сентябрь','10'=>'Октябрь','11'=>'Ноябрь','12'=>'Декабрь');
$day=array('0'=>'Воскресенье','1'=>'Понедельник','2'=>'Вторник','3'=>'Среда','4'=>'Четверг','5'=>'Пятница','6'=>'Суббота');
$color=array(0=>'orange',1=>'green',2=>'red',3=>'yellow',4=>'blue');
if(!isset($_GET['id'])&&!isset($_GET['page'])){//Просмотр всех записей
$blog['name']='Инструкции ЭИОС'; $w['id_category']='';
if (isset($_GET['cat'])) {
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs_category WHERE alt_name="'.get_data_fu($_GET['cat']).'"';
$rez=$DB->QUR_SEL($sql);//echo $sql.mysql_error();
if($rez) {
$blog['name']=out_data_fu($rez[1]['name']);
$w['id_category']=$rez[1]['id'];
}
}
$blog['breadcrumb']=array();//навигационная лента
$blog['breadcrumb'][0]['url']='/';
$blog['breadcrumb'][0]['name']='Инструкции';
$blog['breadcrumb'][1]['url']='/help/';
$blog['breadcrumb'][1]['name']='Инструкции ЭИОС';
$blog['breadcrumb'][1]['active']=1;
$WH='';
if($w['id_category']!=''){
if($WH=='') $WH=' AND '; $WH .= 'id_category='.$w['id_category'];
}
$pagi=pagination_blog('SELECT * FROM '.$ST['dbpf'].'_blogs WHERE status=1'.$WH.'',5);
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs WHERE status=1'.$WH.' ORDER BY zakrep DESC, data_c DESC '.$pagi['limit'];
$rez=$DB->QUR_SEL($sql); //print_r($_GET); echo $sql;
if($rez){
$i=0; foreach($rez as $key => $val)if($key){
$blog['posts'][$i]['d_d']=date('d',$val['data_c']);
$blog['posts'][$i]['d_m']=$mes[date('m',$val['data_c'])];
$blog['posts'][$i]['d_day']=$day[date('w',$val['data_c'])];
$blog['posts'][$i]['time']=date('H:i',$val['data_c']);
$blog['posts'][$i]['view']=$val['views'];
if($val['comment']==1) $blog['posts'][$i]['com_kol']=get_comment_kol('blog',$val['id']);
else $blog['posts'][$i]['com_kol']='';
$blog['posts'][$i]['url']=$val['id'];
$blog['posts'][$i]['name']=out_data_fu($val['title']);
$t=get_user($val['id_user']);
$blog['posts'][$i]['author']=out_data_fu($t['fio']);
$blog['posts'][$i]['img']='';
$blog['posts'][$i]['color']=$color[$i];
$val['text_f'] = str_replace('<div>[page]</div>','[page]',$val['text_f']);
$t = explode('[page]',$val['text_f']);
if (count($t)>1){
$blog['posts'][$i]['text_s']=out_data_fu($t[0]);
//$blog['posts'][$i]['text_f']=out_data_fu($t[1]);
}else{
$blog['posts'][$i]['text_s']=out_data_fu($val['text_f']);
}
$i++;
}
}
}
if(isset($_GET['id'])&&!isset($_GET['page'])){//Просмотр одной записи
$blog['name']='Инструкции ЭИОС'; $w['id_category']='';
if (isset($_GET['cat'])) {
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs_category WHERE alt_name="'.get_data_fu($_GET['cat']).'"';
$rez=$DB->QUR_SEL($sql);//echo $sql.mysql_error();
if($rez) {
$blog['name']=out_data_fu($rez[1]['name']);
$w['id_category']=$rez[1]['id'];
}
}
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs WHERE id='.(int)$_GET['id'].' LIMIT 1';
$rez=$DB->QUR_SEL($sql);
if($rez){
$DB->QUR('UPDATE '.$ST['dbpf'].'_blogs SET views=views+1 WHERE id='.(int)$_GET['id'].' LIMIT 1');
$i=0; foreach($rez as $key => $val)if($key){
$blog['posts'][$i]['d_d']=date('d',$val['data_c']);
$blog['posts'][$i]['d_m']=$mes[date('m',$val['data_c'])];
$blog['posts'][$i]['d_day']=$day[date('w',$val['data_c'])];
$blog['posts'][$i]['time']=date('H:i',$val['data_c']);
$blog['posts'][$i]['view']=$val['views'];
if($val['comment']==1) $blog['posts'][$i]['com_kol']=get_comment_kol('blog',$val['id']);
else $blog['posts'][$i]['com_kol']='';
$blog['posts'][$i]['url']=$val['id'];
$blog['posts'][$i]['name']=$blog['name']=out_data_fu($val['title']);
$t=get_user($val['id_user']);
$blog['posts'][$i]['author']=out_data_fu($t['fio']);
$blog['posts'][$i]['img']='';
$blog['posts'][$i]['color']=$color[rand(0,3)];
$blog['posts'][$i]['comment']=$val['comment'];
$val['text_f'] = str_replace('<div>[page]</div>','[page]',$val['text_f']);
$t = explode('[page]',$val['text_f']);
if (count($t)>1){
$blog['posts'][$i]['text_s']=out_data_fu($t[0]);
$blog['posts'][$i]['text_f']=out_data_fu($t[1]);
}else{
$blog['posts'][$i]['text_f']=out_data_fu($val['text_f']);
}
if($val['comment']==1) $comm=get_comment('blog',$val['id']); else $comm=array();
$blog['posts'][$i]['comm']=$comm;
$i++;
}
}
/*
$blog['comments'][0]=array();
$blog['comments'][0]['user_avatar']='/img/';
$blog['comments'][0]['user_name']='';
$blog['comments'][0]['time']='';
$blog['comments'][0]['text_f']='';
*/
}
//Все категории
$categoryHelp = array();
$sql = 'SELECT * FROM '.$ST['dbpf'].'_help_category WHERE id_main = 0 ORDER BY position';
$rez=$DB->QUR_SEL($sql);
if ($rez){
foreach ($rez as $key => $val) if ($key){
//второй уровень
$sql2 = 'SELECT * FROM '.$ST['dbpf'].'_help_category WHERE id_main = "'.$val['id'].'" ORDER BY position';
$rez2 = $DB->QUR_SEL($sql2);
$val['level2'] = array();
$val['count'] = $rez2[0];
foreach ($rez2 as $key2 => $val2) if ($key2){
//третий уровень
$sql3 = 'SELECT * FROM '.$ST['dbpf'].'_help_category WHERE id_main = "'.$val2['id'].'" ORDER BY position';
$rez3 = $DB->QUR_SEL($sql3);
$val2['level3'] = array();
foreach ($rez3 as $key3 => $val3) if ($key3){
//документы 3 уровня
$val3['docs'] = array();
$sql3_docs = 'SELECT * FROM '.$ST['dbpf'].'_help WHERE id_category = "'.$val3['id'].'" ';
$rez3_docs = $DB->QUR_SEL($sql3_docs);
$val3['count'] = $rez3_docs[0]; //смотрим сколько всего документов внутри
foreach ($rez3_docs as $key3_d => $val3_d) if ($key3_d){
$val3['docs'][] = $val3_d;
}
$val2['level3'][] = $val3;
}
//документы 2 уровня
$val2['docs'] = array();
$sql2_docs = 'SELECT * FROM '.$ST['dbpf'].'_help WHERE id_category = "'.$val2['id'].'" ';
$rez2_docs = $DB->QUR_SEL($sql2_docs);
$val2['count'] = $rez2_docs[0]; //смотрим сколько всего документов внутри
foreach ($rez2_docs as $key2_d => $val2_d) if ($key2_d){
$val2['docs'][] = $val2_d;
}
$val['level2'][] = $val2;
}
//документы 1 уровня
$val['docs'] = array();
$sql_docs = 'SELECT * FROM '.$ST['dbpf'].'_help WHERE id_category = "'.$val['id'].'" ';
$rez_docs = $DB->QUR_SEL($sql_docs);
foreach ($rez_docs as $key_d => $val_d) if ($key_d){
$val['docs'][] = $val_d;
}
$categoryAll[] = $val;
}
}
//print_r($categoryAll);
$view = 0;
$help = array();
//если выбран конкретная страница
if (isset($_GET['id'])){
$view = 1;
$sql = 'SELECT * FROM '.$ST['dbpf'].'_help WHERE id = "'.$_GET['id'].'" ';
$rez = $DB->QUR_SEL($sql);
$help['title'] = $rez[1]['title'];
$help['text_f'] = $rez[1]['text_f'];
}
//ИЩЕМ НЕОБХОДИМЫЙ МАТЕРИАЛ
$search_material = array();
if (isset($_POST['search_string'])){
$view = 2;
$sql = 'SELECT * FROM '.$ST['dbpf'].'_help WHERE text_f LIKE "%'.$_POST['search_string'].'%" ';
$rez = $DB->QUR_SEL($sql);
foreach ($rez as $key => $val) if ($key){
$search_material[] = $val;
}
}
/***********************/
$ST['page']['name'] = $blog['name'];
$smarty->assign('blog',$blog);
$smarty->assign('users_online',$users_online);
$smarty->assign('week',$week);
$smarty->assign('pagination',$pagi);
$smarty->assign('search_material',$search_material);
/***/
$smarty->assign('help',$help);
$smarty->assign('view',$view);
$smarty->assign('is',$isOrder);
$smarty->assign('id_user',$id_user);
$smarty->assign('id_grupp',$_SESSION['user']['student']['id_grupp']);
$smarty->assign('categoryAll',$categoryAll);
$maincontent = $smarty->fetch('tpl_instruction.html');
//$maincontent = '12';
//echo strlen($maincontent);
}
//ПОЛУЧЕНИЕ КОММЕНТАРИЕВ
function get_comment($table,$id){
GLOBAL $ST,$DB; $out=array();
if (isset($_SESSION['user']['id'])){
if(isset($_POST['comm_post'])){//СОХРАНЯЕМ КОММЕНТА
$text_f=get_data_fu($_POST['text_f']);
if (isset($_POST['par'])) $par=(int)get_data_fu($_POST['par']); else $par=0;
$sql='INSERT INTO '.$ST['dbpf'].'_comments VALUES (0,'.mktime().',"'.$table.'",'.$id.','.$par.','.$_SESSION['user']['id'].',"'.$text_f.'",0)';
$rez=$DB->QUR($sql); //echo $sql.mysql_error();
if(!$rez['err']) $out['msg']='Ваш комментарий добавлен!';
else $out['err']='Ваш комментарий не добавлен!';
}
//ОТОБРАЖАЕМ КОММЕНТЫ
$sql='SELECT * FROM '.$ST['dbpf'].'_comments WHERE wtable="'.$table.'" AND id_item='.$id.' ORDER BY data_c';
$rez=$DB->QUR_SEL($sql);
if($rez){
$out['items']=array();
$i=0;foreach($rez as $key => $val)if($key){
$user = get_user($val['id_user']);
if($user['foto']!='')$out['items'][$i]['user_avatar']='/upload/users/ava/'.$val['id_user'].'_ava_150.jpg';
else $out['items'][$i]['user_avatar']='/tpl/img/no_avatar.png';
$out['items'][$i]['user_name']=out_data_fu($user['fio']);
$out['items'][$i]['time']=get_data($val['data_c'],0,1);
$out['items'][$i]['text_f']=out_data_fu($val['text_f']);
$i++;
}
}
}
return $out;
}
//ПОЛУЧЕНИЕ ТОЛЬКО КОЛИЧЕСТВА
function get_comment_kol($table,$id){
GLOBAL $ST,$DB; $out=array();
$sql='SELECT * FROM '.$ST['dbpf'].'_comments WHERE wtable="'.$table.'" AND id_item='.$id.' ORDER BY data_c';
$rez=$DB->QUR_SEL($sql);
if($rez){
$out=$rez[0];
$out .= ' '.getNumEnding($out, array('комментарий', 'комментария', 'комментариев'));
}else{$out='';}
return $out;
}
?>