diff --git a/api2.php b/api2.php index 6df2b23..c1fdd02 100644 --- a/api2.php +++ b/api2.php @@ -10,17 +10,15 @@ $c = $peter_db -> getConnection(); //if (!mysqli_select_db($c, $DBName)) { die("Uh oh, couldn't select database $DBName"); } mysqli_set_charset($c, 'utf8'); -$server = $_SERVER['SERVER_NAME']; $DEBUG = 0; function p($s) { echo "
{$s}
\n"; } function p2($val){ echo ''; print_r($val); echo "\n"; } -function d_err($s) { global $DEBUG; if ($DEBUG) { p($s); } } function ok($str) { global $c; return mysqli_real_escape_string($c, strip_tags($str, '
{$s}
\n"; } function p2($val){ echo ''; print_r($val); echo "\n"; } -function d_err($s) { global $DEBUG; if ($DEBUG) { p($s); } } function logout() { session_destroy(); } // Some helpful globals -$server = $_SERVER['SERVER_NAME']; $options_query = "SELECT label,value FROM `conf_uinforecord` WHERE id>1"; $options_array = multi_row_select($options_query, 0); @@ -96,48 +70,6 @@ function name_to_file($fn,$ln) { return $fn . "_" . $ln . ".jpg"; } -// 1. lookups, like a username -function single_row_select($qry, $j) { global $c; - $r = mysqli_query($c, $qry); d_err($qry); - $e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); } - if (!$r) { return $r; } - //echo("\n\n\n"); - $a = mysqli_fetch_assoc($r); - $e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); } - if (! $j) { return $a; } return json_encode($a); } - -// 1a. inserts -function single_row_insert($qry, $j) { global $c; - error_log($qry, 0); - $r = mysqli_query($c, $qry); - //d_err($qry); - //$e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); } - $new_id = mysqli_insert_id($c); - return $new_id; } - - /*$a = mysqli_fetch_assoc($c); - $e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); } - if (! $j) { return $a; } return json_encode($a); } */ - -// 1b. updates -function single_row_update($qry, $j) { global $c; - $r = mysqli_query($c, $qry); - return 1; } - -// 2. grid or fancier joins, like get all sessions, rosters, todos, etc -function multi_row_select($qry, $j) { global $c; - $rows = array(); - $result = mysqli_query($c, $qry); - while($r = mysqli_fetch_assoc($result)) { $rows[] = $r; } - if (! $j) { return $rows; } return json_encode( $rows); } - - -// 4. Plain query -function query($qry) { - global $c; - return mysqli_query($c, $qry); -} - // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // @@ -192,7 +124,6 @@ function check_dir_photo($fn,$ln) { global $USER; -include('single_sign_on.php'); diff --git a/js/dir_app.js b/js/dir_app.js index 887a288..04c28a9 100644 --- a/js/dir_app.js +++ b/js/dir_app.js @@ -365,7 +365,7 @@ Vue.component('ModePill', { switch (this.mode) { case 'inperson': return 'In Person'; case 'online': return 'Online'; - case 'hybrid': return 'Hybrid'; + case 'hybrid': return 'Hyflex'; default: return this.mode; } }, @@ -2565,7 +2565,7 @@ var app = new Vue({ sessiontypes_menu: [], parents_menu: [], ay_menu: [], - modes_menu: [ {'id': 'Pending', 'string':'Pending'}, {'id':'online','string':'Online'}, {'id':'inperson','string':'In Person'}, {'id':'hybrid','string':'Hybrid'}, {'id':'','string':''}, ], + modes_menu: [ {'id': 'Pending', 'string':'Pending'}, {'id':'online','string':'Online'}, {'id':'inperson','string':'In Person'}, {'id':'hybrid','string':'Hyflex'}, {'id':'','string':''}, ], waiting_fxns: [], data_loaded: 0, committees_menu: [], diff --git a/layout.php b/layout.php index bc449af..6834c1d 100644 --- a/layout.php +++ b/layout.php @@ -1,7 +1,14 @@ getConnection(); + +require_once('single_sign_on.php'); + +require_once('semester.php'); if (!isset($MY_TITLE)) $MY_TITLE = "Untitled Page"; if (!isset($MY_CRUMB)) $MY_CRUMB = $MY_TITLE; diff --git a/single_sign_on.php b/single_sign_on.php index f45c367..16a3f9a 100644 --- a/single_sign_on.php +++ b/single_sign_on.php @@ -14,8 +14,66 @@ // They may only edit their own dir info. // +include_once("peter_db.php"); +$peter_db = new peter_db(); +$c = $peter_db -> getConnection(); + + +$server = $_SERVER['SERVER_NAME']; + +$IS_PROD = 0; +if ( $server == 'www.gavilan.edu') { $IS_PROD = 1; } + + + date_default_timezone_set('America/Los_Angeles'); +// 1. lookups, like a username +function single_row_select($qry, $j) { global $c; + $r = mysqli_query($c, $qry); d_err($qry); + $e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); } + if (!$r) { return $r; } + //echo("\n\n\n"); + $a = mysqli_fetch_assoc($r); + $e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); } + if (! $j) { return $a; } return json_encode($a); } + +// 1a. inserts +function single_row_insert($qry, $j) { global $c; + error_log($qry, 0); + $r = mysqli_query($c, $qry); + //d_err($qry); + //$e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); } + $new_id = mysqli_insert_id($c); + return $new_id; } + + /*$a = mysqli_fetch_assoc($c); + $e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); } + if (! $j) { return $a; } return json_encode($a); } */ + +// 1b. updates +function single_row_update($qry, $j) { global $c; + $r = mysqli_query($c, $qry); + return 1; } + +// 2. grid or fancier joins, like get all sessions, rosters, todos, etc +function multi_row_select($qry, $j) { global $c; + $rows = array(); + $result = mysqli_query($c, $qry); + while($r = mysqli_fetch_assoc($result)) { $rows[] = $r; } + if (! $j) { return $rows; } return json_encode( $rows); } + + +// 4. Plain query +function query($qry) { + global $c; + return mysqli_query($c, $qry); +} + +function d_err($s) { global $DEBUG; if ($DEBUG) { p($s); } } + + + // 3. Check if an entry exists function does_exist($qry, $full_record) { global $c; $r = mysqli_query($c, $qry); @@ -38,7 +96,7 @@ function dumpit($var) { function insert_or_get_browser($b) { global $c; - $BROWSER = ok($b); + $BROWSER = $b; // ok($b); $existing = does_exist( "SELECT id FROM www_browsers WHERE string='$BROWSER'", 0); if ($existing) { return $existing; } else { @@ -58,7 +116,8 @@ function log_it($action, $user=860) { $user_ip = $_SERVER['REMOTE_ADDR']; $BROWSER = insert_or_get_browser($user_browser); - $ACTION = ok($action) . " / " . dumpit($USER) . " / " . $USER_GOO . " / " . $USER_EMAIL; + //$ACTION = ok($action) . " / " . dumpit($USER) . " / " . $USER_GOO . " / " . $USER_EMAIL; + $ACTION = $action . " / " . dumpit($USER) . " / " . $USER_GOO . " / " . $USER_EMAIL; //$persid = $USER->id; //if (! $persid) { $persid = -1; } @@ -74,14 +133,20 @@ exit(); $auth_script = "mAuth.php"; -if (file_exists($auth_script)) { +log_it($IS_PROD); + +//if (file_exists($auth_script)) { +if ($IS_PROD) { require_once($auth_script); $USER_TYPE = $attributes['Roles'][0]; $USER_GOO = $attributes['uid'][0]; $USER_EMAIL = $attributes['EmailGC'][0]; + log_it("mauth returned user_type=$USER_TYPE, user_goo=$USER_GOO, user_email=$USER_EMAIL."); + session_start(); $SESSION_ID = session_id(); + log_it("new session: " . $SESSION_ID); //if ( $SESSION_ID == '' ) { // session_status() == PHP_SESSION_ACTIVE // newer php uses this if ( session_status() == PHP_SESSION_ACTIVE ) { // // newer php uses this $_SESSION['USER_TYPE'] = $USER_TYPE; @@ -101,6 +166,7 @@ if (file_exists($auth_script)) { $_SESSION['USER_TYPE'] = $USER_TYPE; $_SESSION['USER_GOO'] = $USER_GOO; $_SESSION['USER_EMAIL'] = $USER_EMAIL; + log_it("mauth failed."); } // The SSO check should have happened on the actual page. If it gets // stuck on an api call the app will break.