cat_ID===NEWS_CAT_ID){$IS_NEWS_POST=true; $container_htmlid = 'container-news-post'; break;} elseif($c->cat_ID===CALENDAR_CAT_ID){$IS_AIA_CALENDAR_POST=true; $container_htmlid = 'container-aiacalendar-post'; break;} elseif($c->cat_ID===LECTURER_CAT_ID){$IS_LECTURER_POST=true; $container_htmlid = 'container-lectures-post'; break;} elseif($c->cat_ID===TECH_VIDEO_CAT_ID or $c->parent==TECH_VIDEO_CAT_ID){$IS_TECH_VIDEO_POST=true; $container_htmlid = 'container-techvideo-post'; break;} } $ary_can_view_calendar_wpuser = array('vansindata', "tclin",'yidar'); if($IS_AIA_CALENDAR_POST){ $wp_user = wp_get_current_user(); $can_view_aia_calendar = !!$wp_user->user_login; # [2019.10.4] for AIA staffs with wordpress account # in_array($wp_user->user_login, $ary_can_view_calendar_wpuser); if(!$can_view_aia_calendar){ $aia_calendar_url = str_replace('/','', explode('?',$_SERVER['REQUEST_URI'])[0] ); $allow_school_no_substr5 = explode('-', $aia_calendar_url)[1]; $KEYCLOAK_USER = get_keycloak_user_by_session_or_cache(); if($KEYCLOAK_USER){ $a = $KEYCLOAK_USER->toArray(); if((is_student_had_the_class($a['groups'], $allow_school_no_substr5)) # [2019.10.4] for students with keycloak account or can_view_aia_calendar_keycloak_user($a['preferred_username']) # [2019.10.4] for AIA staffs with keycloak account ){ $can_view_aia_calendar = true; } }elseif(is_aia_student_login()){ $preferred_username = get_aia_student_school_no(); # [2019.10.4] for students with custom login session if(strpos($preferred_username, $allow_school_no_substr5)===0){ $can_view_aia_calendar = true; } } } if(!$can_view_aia_calendar){ if($wp_user->user_login){ die('Hi '.$wp_user->user_login.', you cannot view this calendar page, please contact Web Developer.'); }else{ $preferred_username = is_aia_student_login() ? get_aia_student_school_no() : (isset($a['preferred_username']) ? $a['preferred_username'] : ''); die('您無法查看 '.explode('?',$_SERVER['REQUEST_URI'])[0].' 課程表,請確認您的帳號與權限是否正確。您目前登入的學生帳號為:【' .$preferred_username .'】' ); } } } # end of if($IS_AIA_CALENDAR_POST) # valid student can view video or not START if($IS_TECH_VIDEO_POST){ $can_view_this_video = false; $post_id = get_the_ID(); $limit_at_join_no = get_post_meta($post_id, 'limit_at_join_no',true); #old way $limit_at_place = strtolower(trim(get_post_meta($post_id, 'limit_at_place',true))); #old way if($limit_at_join_no_and_place = get_post_meta($post_id, 'limit_at_join_no_and_place', true)){ #new way: allow multiple schools $limit_at_join_no_and_place = explode(',',$limit_at_join_no_and_place); } $cur_join_no = ''; $cur_area_code = ''; $KEYCLOAK_USER = get_keycloak_user_by_session_or_cache(); if(!$can_view_this_video and !isset($_GET['debug_using_keycloak_student_only'])){ $user = wp_get_current_user(); if(is_staff_can_view_video($user->user_login)){ # [2019.10.4] for AIA staffs with wordpress account $can_view_this_video=true; } } if(!$can_view_this_video){ if($KEYCLOAK_USER || is_aia_student_login()){ # [2019.10.4] students with keycloak || custom session login if($KEYCLOAK_USER){ $a = $KEYCLOAK_USER->toArray(); $school_no = get_recent_school_no_from_keycloak_groups($a['groups']); }else{ $school_no = get_aia_student_school_no(); } if(!is_has_video_xlass($school_no) and (!isset($a) or !can_view_aia_video_keycloak_user($a['preferred_username']))) { header('location:'.WEB_URL.'?uioklxczv'); exit; } $cur_join_no = get_student_join_no($school_no); $cur_area_code = get_student_area_code($school_no); if($cur_join_no==$limit_at_join_no and $cur_area_code==$limit_at_place){ #old way: only allow one school $can_view_this_video = true; }elseif(strtolower($school_no)===SCHOOL_PRINCIPAL_TECH_ACCOUNT and $limit_at_place==TAIPEI_AREA_CODE){ // 20181018: This account can view all taipei for school principal $can_view_this_video = true; } if(!$can_view_this_video and $KEYCLOAK_USER){ $a = $KEYCLOAK_USER->toArray(); $can_view_this_video = can_view_aia_video_keycloak_user($a['preferred_username']); # [2019.10.4] for AIA staffs with keycloak account } if(!$can_view_this_video){ foreach($limit_at_join_no_and_place as$_){ list($course_date, $limit_at_place, $limit_at_join_no) = explode('-', $_); if($cur_join_no==$limit_at_join_no and $cur_area_code==$limit_at_place){ #old way: only allow one school $can_view_this_video = true; break; } } } } } if(!$can_view_this_video){ $uri = $_SERVER['REQUEST_URI']; if(strpos($uri,'?')!==false){$uri = explode('?', $uri)[0];} $allowing_msg = ''; if($limit_at_join_no_and_place = get_post_meta($post_id,'limit_at_join_no_and_place',true)){ $limit_at_join_no_and_place = explode(',',$limit_at_join_no_and_place); foreach($limit_at_join_no_and_place as$_){ list($course_date, $limit_at_place, $limit_at_join_no) = explode('-', $_); $allowing_msg .= '【'.$ARY_STUDENT_AREA_CODE[$limit_at_place].'第'.$limit_at_join_no.'期】'; } }else{ $allowing_msg = '【'.$ARY_STUDENT_AREA_CODE[$limit_at_place].'】【第 '.$limit_at_join_no.' 期】'; } die('Hi '.strtoupper($school_no).' 您好:本頁 '.$uri.' 僅開放給' .$allowing_msg .'的學生觀看影片,您是屬於【' .($cur_area_code ? $ARY_STUDENT_AREA_CODE[$cur_area_code] : '') .'】【第 '.$cur_join_no.' 期】的學生。 (回首頁)' ); } } # valid student can view video or not END ?>