function char_class($char) { $ret = is_cyr($char) ? '0001' : (is_space($char) ? '0010' : (is_dot($char) ? '0011' : (is_pmark($char) ? '0100' : (is_hyphen($char) ? '0101' : (is_number($char) ? '0110' : (is_latin($char) ? '0111' : (is_bracket1($char) ? '1000' : (is_bracket2($char) ? '1001' : (is_single_quote($char) ? '1010' : (is_slash($char) ? '1011' : (is_colon($char) ? '1100' : '0000'))))))))))); return str_split($ret); }
function makequery($q, $ssource, $starget, $year) { global $title_lang, $item_pre_page; $select = array(); $where = ""; //$order = array(); if (is_latin($q)) { $title_lang = 'en'; } switch ($ssource) { case 'all': $select['select1'] = "(SELECT t.id as 'thesis_id', t.title as 'thesis_title', concat_ws(' ',u.fname,u.lname) as 'thesis_fullname', t.date as 'thesis_date', t.f_id as 'thesis_fId', null as 'article_id', null as 'article_title',null as 'article_title_en', null as 'article_fullname', null as 'article_date', null as 'article_file' from `thesis` as t"; $select['join1'] = ''; $select['where1'] = ''; $select['year1'] = ''; $select[] = "ORDER BY t.id DESC"; $select['limit1'] = ')'; $select[] = 'UNION'; $select['select2'] = "(SELECT null,null,null,null,null,a.id,a.title,a.title_en,concat_ws(' ',u.fname,u.lname),a.date,a.file from `article` as a"; $select['join2'] = ''; $select['where2'] = ''; $select['year2'] = ''; $select[] = "ORDER BY a.id DESC"; $select['limit2'] = ')'; break; case 'thesis': $select['select1'] = "(SELECT t.id as 'thesis_id', t.title as 'thesis_title', concat_ws(' ',u.fname,u.lname) as 'thesis_fullname', t.date as 'thesis_date' from `thesis` as t"; $select['join1'] = ''; $select['where1'] = ''; $select['year1'] = ''; $select[] = "ORDER BY t.id DESC"; $select['limit1'] = ')'; break; case 'article': $select['select1'] = "(SELECT a.id as 'article_id', a.title as 'article_title', a.title_en as 'article_title_en', concat_ws(' ',u.fname,u.lname) as 'article_fullname', a.date as 'article_date', a.file as 'article_file' from `article` as a"; $select['join1'] = ''; $select['field_join'] = ''; $select['where1'] = ''; $select['year1'] = ''; $select[] = "ORDER BY a.id DESC"; $select['limit1'] = ')'; break; } switch ($starget) { case 'all': $where = " WHERE "; $join1 = "inner join user as u on t.uId = u.id"; $join2 = "inner join user as u on a.uId = u.id"; if ($ssource == 'all') { $select['join1'] = $join1; $select['join2'] = $join2; $select['where1'] = "WHERE t.title like " . search_parameter($q) . " OR concat_ws(' ',u.fname,u.lname) like " . search_parameter($q) . " OR t.keyword like " . search_parameter($q); $select['where2'] = "WHERE a.title like " . search_parameter($q) . " OR concat_ws(' ',u.fname,u.lname) like " . search_parameter($q) . " OR a.keyword like " . search_parameter($q) . " OR a.keyword_en like " . search_parameter($q) . " OR a.title_en like " . search_parameter($q); } else { if ($ssource == 'thesis') { $select['join1'] = $join1; $select['where1'] = "WHERE t.title like " . search_parameter($q) . " OR concat_ws(' ',u.fname,u.lname) like " . search_parameter($q) . " OR t.keyword like " . search_parameter($q); //$where = "t.title like %".search_parameter($q)."%"; } else { if ($ssource == 'article') { $select['join1'] = $join2; $select['where1'] = "WHERE a.title like " . search_parameter($q) . " OR concat_ws(' ',u.fname,u.lname) like " . search_parameter($q) . " OR a.keyword like " . search_parameter($q) . " OR a.keyword_en like " . search_parameter($q) . " OR a.title_en like " . search_parameter($q); //$where = "a.title like %".search_parameter($q)."% OR a.title_en like %".search_parameter($q)."%"; } } } break; case 'title': if (is_latin($q)) { $title_lang = 'en'; } $join1 = "inner join user as u on t.uId = u.id"; $join2 = "inner join user as u on a.uId = u.id"; if ($ssource == 'all') { $select['join1'] = $join1; $select['join2'] = $join2; $select['where1'] = "WHERE t.title like " . search_parameter($q); $select['where2'] = "WHERE a.title like " . search_parameter($q) . " OR a.title_en like " . search_parameter($q); //$where = " WHERE t.title like %".search_parameter($q)."% OR a.title like %".search_parameter($q)."% OR a.title_en like %".search_parameter($q)."%"; } else { if ($ssource == 'thesis') { $select['join1'] = $join1; $select['where1'] = "WHERE t.title like " . search_parameter($q); //$where = " WHERE t.title like %".search_parameter($q)."%"; } else { if ($ssource == 'article') { $select['join1'] = $join2; $select['where1'] = "WHERE a.title like " . search_parameter($q) . " OR a.title_en like " . search_parameter($q); //$where = " WHERE a.title like %".search_parameter($q)."% OR a.title_en like %".search_parameter($q)."%"; } } } break; case 'author': $join = "inner join user as u on concat_ws(' ',u.fname,u.lname) like " . search_parameter($q); if ($ssource == 'all') { $select['join1'] = $join; $select['join2'] = $join; $select['where1'] = "WHERE t.uId = u.id"; $select['where2'] = "WHERE a.uId = u.id"; } else { if ($ssource == 'thesis') { $select['join1'] = $join; $select['where1'] = "WHERE t.uId = u.id"; //$where = " WHERE concat_ws(' ',t.fname,t.lname) like %".search_parameter($q)."%"; } else { if ($ssource == 'article') { $select['join1'] = $join; $select['where1'] = "WHERE a.uId = u.id"; //$where = " WHERE concat_ws(' ',a.fname,a.lname) like %".search_parameter($q)."%"; } } } break; case 'keywords': if (is_latin($q)) { $title_lang = 'en'; } $join1 = "inner join user as u on t.uId = u.id"; $join2 = "inner join user as u on a.uId = u.id"; if ($ssource == 'all') { $select['join1'] = $join1; $select['join2'] = $join2; $select['where1'] = "WHERE t.keyword like " . search_parameter($q); $select['where2'] = "WHERE a.keyword like " . search_parameter($q) . " OR a.keyword_en like " . search_parameter($q); } else { if ($ssource == 'thesis') { $select['join1'] = $join1; $select['where1'] = "WHERE t.keyword like " . search_parameter($q); //$where = " WHERE t.keyword like %".search_parameter($q)."%"; } else { if ($ssource == 'article') { $select['join1'] = $join2; $select['where1'] = "WHERE a.keyword like " . search_parameter($q) . " OR a.keyword_en like " . search_parameter($q); //$where = " WHERE a.keyword like %".search_parameter($q)."% OR a.keyword_en like %".search_parameter($q)."%"; } } } break; } if (intval($year) && is_numeric($year)) { if ($ssource == 'all') { $select['year1'] = ' AND YEAR(t.date)=' . search_parameter($year, false); $select['year2'] = ' AND YEAR(a.date)=' . search_parameter($year, false); } else { if ($ssource == 'thesis') { $select['year1'] = ' AND YEAR(t.date)=' . search_parameter($year, false); } else { if ($ssource == 'article') { $select['year1'] = ' AND YEAR(a.date)=' . search_parameter($year, false); } } } } #SELECT ACTIVE ARTICLE AND THESIS# if ($ssource == 'all') { $select['where1'] = $select['where1'] . " AND t.status = 1"; $select['where2'] = $select['where2'] . " AND a.status = 1"; } else { if ($ssource == 'thesis') { $select['where1'] = $select['where1'] . " AND t.status = 1"; } else { if ($ssource == 'article') { $select['where1'] = $select['where1'] . " AND a.status = 1"; } } } #Multi Field Search if ($ssource == 'article' && isset($_POST['field']) && !empty($_POST['field'])) { $select['field_join'] = "inner join article_field as af on a.id = af.aId"; $select['where1'] = $select['where1'] . " AND af.fId in(" . search_parameter($_POST['field'], false) . ")"; } $page = 1; if (isset($_GET['page']) && !empty($_GET['page']) && is_numeric($_GET['page']) && intval($_GET['page'])) { $page = abs(filter_var($_GET['page'], FILTER_SANITIZE_STRING)); } $start = abs(($page - 1) * $item_pre_page); $end = $item_pre_page; if ($ssource == 'all') { $select['limit1'] = ' LIMIT ' . $start . ', ' . $end . ')'; $select['limit2'] = ' LIMIT ' . $start . ', ' . $end . ')'; } else { if ($ssource == 'thesis') { $select['limit1'] = ' LIMIT ' . $start . ', ' . $end . ')'; } else { if ($ssource == 'article') { $select['limit1'] = ' LIMIT ' . $start . ', ' . $end . ')'; } } } $select = array_filter($select); $count = $select; if ($ssource == 'all') { $count['select1'] = "(select count(*) as `count` from `thesis` as t"; $count['limit1'] = ')'; $count['select2'] = "(select count(*) from `article` as a"; $count['limit2'] = ')'; } else { if ($ssource == 'thesis') { $count['select1'] = "(select count(*) as `count` from `thesis` as t"; $count['limit1'] = ')'; } else { if ($ssource == 'article') { $count['select1'] = "(select count(*) as `count` from `article` as a"; $count['limit1'] = ')'; } } } $count = array_filter($count); $select = implode("\n", $select); $count = implode("\n", $count); $query = array('select' => $select, 'count' => $count); return $query; }
function article($pdo) { global $_LANGUAGE; if (isset($_GET['teacher']) && !empty($_GET['teacher']) && intval($_GET['teacher'])) { $html = array(); $id = intval($_GET['teacher']); $template = '<div class="teacher_article"> <div class="title"><img src="' . BASE_PATH . '/assets/img/article.png" align="absmiddle"/> {title}{remove}</div> <div>  ' . $_LANGUAGE['teacher_article_info'][DEFAULT_LANGUAGE] . ':</div> <div> ' . $_LANGUAGE['date'][DEFAULT_LANGUAGE] . ': {date} </div> <div> ' . $_LANGUAGE['teacher_article_loc'][DEFAULT_LANGUAGE] . ': {place}</div> <div> ' . $_LANGUAGE['teacher_article_presentation'][DEFAULT_LANGUAGE] . ': {presentation}</div> <div> ' . $_LANGUAGE['teacher_article_link'][DEFAULT_LANGUAGE] . ': {link}</div> </div>'; $remove = '<a href="javascript:void(0)" class="tooltip" title="' . $_LANGUAGE['tooltip_remove'][DEFAULT_LANGUAGE] . '" onclick=\'if(confirm('Are you sure?')) {window.location="' . BASE_PATH . '/teacher/?do=delete&article={id}&token=' . $_SESSION['token'] . '" }else{ return false; }\'>X</a>'; $sql = "select * from teacher_article where uid=:id"; $stmt = $pdo->prepare($sql); $stmt->bindvalue(':id', $id, PDO::PARAM_INT); $stmt->execute(); if ($stmt->rowCount()) { $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($rows as $row) { $tpl = $template; if (is_latin($row['title'])) { $tpl = str_replace('{title}', '<div align="left">' . $row['title'] . '</div>', $tpl); } else { $tpl = str_replace('{title}', $row['title'], $tpl); } if (isset($_SESSION['login']) && ($_SESSION['permission'] == 'teacher' || $_SESSION['permission'] == 'admin')) { $r = $remove; $r = str_replace('{id}', $row['id'], $r); $tpl = str_replace('{remove}', $r, $tpl); } else { $tpl = str_replace('{remove}', '', $tpl); } $tpl = str_replace('{date}', $row['date'], $tpl); $tpl = str_replace('{presentation}', $row['presentation'], $tpl); $tpl = str_replace('{link}', $row['link'], $tpl); $html[] = $tpl; } if (!empty($html)) { echo implode("\n", $html); } } else { echo '<center><h3>' . $_LANGUAGE['no_data_display'][DEFAULT_LANGUAGE] . '</h3></center>'; } } }