working version
This commit is contained in:
parent
75b1dbe9f1
commit
7a9ef13da1
5
api2.php
5
api2.php
|
|
@ -10,17 +10,15 @@ $c = $peter_db -> getConnection();
|
||||||
//if (!mysqli_select_db($c, $DBName)) { die("Uh oh, couldn't select database $DBName"); }
|
//if (!mysqli_select_db($c, $DBName)) { die("Uh oh, couldn't select database $DBName"); }
|
||||||
mysqli_set_charset($c, 'utf8');
|
mysqli_set_charset($c, 'utf8');
|
||||||
|
|
||||||
$server = $_SERVER['SERVER_NAME'];
|
|
||||||
$DEBUG = 0;
|
$DEBUG = 0;
|
||||||
function p($s) { echo "<p>{$s}</p>\n"; }
|
function p($s) { echo "<p>{$s}</p>\n"; }
|
||||||
function p2($val){ echo '<pre>'; print_r($val); echo "</pre>\n"; }
|
function p2($val){ echo '<pre>'; print_r($val); echo "</pre>\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, '<p><br><ul><ol><li><b><i><strong><em>')); }
|
function ok($str) { global $c; return mysqli_real_escape_string($c, strip_tags($str, '<p><br><ul><ol><li><b><i><strong><em>')); }
|
||||||
function okh($str) { global $c; return mysqli_real_escape_string($c, $str); }
|
function okh($str) { global $c; return mysqli_real_escape_string($c, $str); }
|
||||||
function sanitizeAndValidate($s) { return okh($s); }
|
function sanitizeAndValidate($s) { return okh($s); }
|
||||||
function unescape_commas($s) { return preg_replace('/\[CMA\]/', ',', $s); }
|
function unescape_commas($s) { return preg_replace('/\[CMA\]/', ',', $s); }
|
||||||
|
|
||||||
function single_row_select($qry, $j=1) {
|
/*function single_row_select($qry, $j=1) {
|
||||||
global $c;
|
global $c;
|
||||||
$r = mysqli_query($c, $qry); d_err($qry);
|
$r = mysqli_query($c, $qry); d_err($qry);
|
||||||
$e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); }
|
$e = mysqli_error($c); if($e) { d_err("sql error: " . $e ); }
|
||||||
|
|
@ -41,6 +39,7 @@ function multi_row_select($qry, $j=1) { global $c; $rows = array();
|
||||||
$result = mysqli_query($c, $qry);
|
$result = mysqli_query($c, $qry);
|
||||||
while($r = mysqli_fetch_assoc($result)) { $rows[] = $r; }
|
while($r = mysqli_fetch_assoc($result)) { $rows[] = $r; }
|
||||||
if (! $j) { return $rows; } return json_encode( $rows); }
|
if (! $j) { return $rows; } return json_encode( $rows); }
|
||||||
|
*/
|
||||||
|
|
||||||
function multi_row_1d($qry) { global $c;
|
function multi_row_1d($qry) { global $c;
|
||||||
$savedQuery = mysqli_query($c, $qry);
|
$savedQuery = mysqli_query($c, $qry);
|
||||||
|
|
|
||||||
2
auth.php
2
auth.php
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$server = $_SERVER['SERVER_NAME'];
|
$server = $_SERVER['SERVER_NAME'];
|
||||||
//echo("The servier name is ****************** $server");
|
echo("The servier name is ****************** $server");
|
||||||
if ( $server == 'www.gavilan.edu') {
|
if ( $server == 'www.gavilan.edu') {
|
||||||
require 'mAuth.php';
|
require 'mAuth.php';
|
||||||
|
|
||||||
|
|
|
||||||
71
dir_api.php
71
dir_api.php
|
|
@ -1,8 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
include_once("peter_db.php");
|
|
||||||
$peter_db = new peter_db();
|
|
||||||
$c = $peter_db -> getConnection();
|
|
||||||
|
|
||||||
$DEBUG = 0;
|
$DEBUG = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,29 +13,9 @@ $DEBUG = 0;
|
||||||
//
|
//
|
||||||
// The $j argument is true for a json result, or false for a raw db object result.
|
// The $j argument is true for a json result, or false for a raw db object result.
|
||||||
//
|
//
|
||||||
/**
|
|
||||||
$TESTSITE = 0;
|
|
||||||
|
|
||||||
if ($TESTSITE) {
|
|
||||||
$DBUser2 = 'phowell'; $DBServer = '192.168.1.6';
|
|
||||||
$DBPass2 = 'rolley34'; $DBName2 = 'db';
|
|
||||||
} else {
|
|
||||||
$DBUser2 = 'phowell'; $DBServer = 'localhost';
|
|
||||||
$DBPass2 = 'p^howell'; $DBName2 = 'PeterDB';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* # not using www account anymore
|
|
||||||
$c = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
|
|
||||||
if ($c->connect_error) { die('Database connection failed: ' . $c->connect_error ); }
|
|
||||||
if (!mysqli_select_db($c, $DBName)) { die("Uh oh, couldn't select database $DBName"); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
//$c = new mysqli($DBServer, $DBUser2, $DBPass2, $DBName2);
|
|
||||||
|
|
||||||
|
|
||||||
|
include('single_sign_on.php');
|
||||||
if ($c->connect_error) { die('Database connection failed: ' . $c->connect_error ); }
|
|
||||||
//if (!mysqli_select_db($c, $DBName2)) { die("Uh oh, couldn't select database 'PeterDB'"); }
|
|
||||||
mysqli_set_charset($c, 'utf8');
|
mysqli_set_charset($c, 'utf8');
|
||||||
|
|
||||||
include('underscore.php');
|
include('underscore.php');
|
||||||
|
|
@ -63,12 +39,10 @@ function unescape_commas($s) { return preg_replace('/\[CMA\]/', ',', $s); }
|
||||||
|
|
||||||
function p($s) { echo "<p>{$s}</p>\n"; }
|
function p($s) { echo "<p>{$s}</p>\n"; }
|
||||||
function p2($val){ echo '<pre>'; print_r($val); echo "</pre>\n"; }
|
function p2($val){ echo '<pre>'; print_r($val); echo "</pre>\n"; }
|
||||||
function d_err($s) { global $DEBUG; if ($DEBUG) { p($s); } }
|
|
||||||
function logout() { session_destroy(); }
|
function logout() { session_destroy(); }
|
||||||
|
|
||||||
// Some helpful globals
|
// Some helpful globals
|
||||||
|
|
||||||
$server = $_SERVER['SERVER_NAME'];
|
|
||||||
$options_query = "SELECT label,value FROM `conf_uinforecord` WHERE id>1";
|
$options_query = "SELECT label,value FROM `conf_uinforecord` WHERE id>1";
|
||||||
$options_array = multi_row_select($options_query, 0);
|
$options_array = multi_row_select($options_query, 0);
|
||||||
|
|
||||||
|
|
@ -96,48 +70,6 @@ function name_to_file($fn,$ln) {
|
||||||
return $fn . "_" . $ln . ".jpg"; }
|
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" . $qry . "\n\n" . json_encode($r) . "\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');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -365,7 +365,7 @@ Vue.component('ModePill', {
|
||||||
switch (this.mode) {
|
switch (this.mode) {
|
||||||
case 'inperson': return 'In Person';
|
case 'inperson': return 'In Person';
|
||||||
case 'online': return 'Online';
|
case 'online': return 'Online';
|
||||||
case 'hybrid': return 'Hybrid';
|
case 'hybrid': return 'Hyflex';
|
||||||
default: return this.mode;
|
default: return this.mode;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -2565,7 +2565,7 @@ var app = new Vue({
|
||||||
sessiontypes_menu: [],
|
sessiontypes_menu: [],
|
||||||
parents_menu: [],
|
parents_menu: [],
|
||||||
ay_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: [],
|
waiting_fxns: [],
|
||||||
data_loaded: 0,
|
data_loaded: 0,
|
||||||
committees_menu: [],
|
committees_menu: [],
|
||||||
|
|
|
||||||
11
layout.php
11
layout.php
|
|
@ -1,7 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
// layout.php (Tailwind version)
|
// layout.php (Tailwind version)
|
||||||
require_once 'auth.php';
|
//require_once 'auth.php';
|
||||||
require_once 'semester.php';
|
|
||||||
|
include_once("peter_db.php");
|
||||||
|
$peter_db = new peter_db();
|
||||||
|
$c = $peter_db -> getConnection();
|
||||||
|
|
||||||
|
require_once('single_sign_on.php');
|
||||||
|
|
||||||
|
require_once('semester.php');
|
||||||
|
|
||||||
if (!isset($MY_TITLE)) $MY_TITLE = "Untitled Page";
|
if (!isset($MY_TITLE)) $MY_TITLE = "Untitled Page";
|
||||||
if (!isset($MY_CRUMB)) $MY_CRUMB = $MY_TITLE;
|
if (!isset($MY_CRUMB)) $MY_CRUMB = $MY_TITLE;
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,66 @@
|
||||||
// They may only edit their own dir info.
|
// 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');
|
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" . $qry . "\n\n" . json_encode($r) . "\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
|
// 3. Check if an entry exists
|
||||||
function does_exist($qry, $full_record) { global $c;
|
function does_exist($qry, $full_record) { global $c;
|
||||||
$r = mysqli_query($c, $qry);
|
$r = mysqli_query($c, $qry);
|
||||||
|
|
@ -38,7 +96,7 @@ function dumpit($var) {
|
||||||
|
|
||||||
function insert_or_get_browser($b) {
|
function insert_or_get_browser($b) {
|
||||||
global $c;
|
global $c;
|
||||||
$BROWSER = ok($b);
|
$BROWSER = $b; // ok($b);
|
||||||
$existing = does_exist( "SELECT id FROM www_browsers WHERE string='$BROWSER'", 0);
|
$existing = does_exist( "SELECT id FROM www_browsers WHERE string='$BROWSER'", 0);
|
||||||
if ($existing) { return $existing;
|
if ($existing) { return $existing;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -58,7 +116,8 @@ function log_it($action, $user=860) {
|
||||||
$user_ip = $_SERVER['REMOTE_ADDR'];
|
$user_ip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
||||||
$BROWSER = insert_or_get_browser($user_browser);
|
$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;
|
//$persid = $USER->id;
|
||||||
//if (! $persid) { $persid = -1; }
|
//if (! $persid) { $persid = -1; }
|
||||||
|
|
@ -74,14 +133,20 @@ exit();
|
||||||
|
|
||||||
$auth_script = "mAuth.php";
|
$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);
|
require_once($auth_script);
|
||||||
$USER_TYPE = $attributes['Roles'][0];
|
$USER_TYPE = $attributes['Roles'][0];
|
||||||
$USER_GOO = $attributes['uid'][0];
|
$USER_GOO = $attributes['uid'][0];
|
||||||
$USER_EMAIL = $attributes['EmailGC'][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_start();
|
||||||
$SESSION_ID = session_id();
|
$SESSION_ID = session_id();
|
||||||
|
log_it("new session: " . $SESSION_ID);
|
||||||
//if ( $SESSION_ID == '' ) { // session_status() == PHP_SESSION_ACTIVE // newer php uses this
|
//if ( $SESSION_ID == '' ) { // session_status() == PHP_SESSION_ACTIVE // newer php uses this
|
||||||
if ( session_status() == PHP_SESSION_ACTIVE ) { // // newer php uses this
|
if ( session_status() == PHP_SESSION_ACTIVE ) { // // newer php uses this
|
||||||
$_SESSION['USER_TYPE'] = $USER_TYPE;
|
$_SESSION['USER_TYPE'] = $USER_TYPE;
|
||||||
|
|
@ -101,6 +166,7 @@ if (file_exists($auth_script)) {
|
||||||
$_SESSION['USER_TYPE'] = $USER_TYPE;
|
$_SESSION['USER_TYPE'] = $USER_TYPE;
|
||||||
$_SESSION['USER_GOO'] = $USER_GOO;
|
$_SESSION['USER_GOO'] = $USER_GOO;
|
||||||
$_SESSION['USER_EMAIL'] = $USER_EMAIL;
|
$_SESSION['USER_EMAIL'] = $USER_EMAIL;
|
||||||
|
log_it("mauth failed.");
|
||||||
}
|
}
|
||||||
// The SSO check should have happened on the actual page. If it gets
|
// The SSO check should have happened on the actual page. If it gets
|
||||||
// stuck on an api call the app will break.
|
// stuck on an api call the app will break.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue