Skip to content

Commit

Permalink
admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
caldwellc1 committed Mar 2, 2020
1 parent 3055497 commit 7296b11
Show file tree
Hide file tree
Showing 17 changed files with 439 additions and 180 deletions.
17 changes: 3 additions & 14 deletions boost/updates/update_01.00.00.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
--reason for admin stop that only they see
--reason for stop that user sees
--Warning, Stop
--name to check sup on flag
--see about having this as Admin Setting
CREATE TABLE intern_special_host(
id INT NOT NULL,
admin_message VARCHAR NOT NULL,
Expand All @@ -14,20 +9,16 @@ CREATE TABLE intern_special_host(
PRIMARY KEY(id)
);

--overall host name
--flag to show if a new host or one that is awaiting approval 0=not approved 1=approve 2=awaiting
CREATE TABLE intern_host (
id INT NOT NULL,
host_name VARCHAR NOT NULL,
host_condition INT REFERENCES intern_special_host(id),
host_condition INT DEFAULT NULL REFERENCES intern_special_host(id),
host_condition_date VARCHAR,
host_approve_flag INT NOT NULL DEFAULT 2,
host_notes VARCHAR,
PRIMARY KEY(id)
);

--sub name of host that will contain the address information
--flag to show if a new host or one that is awaiting approval 0=not approved 1=approve 2=awaiting
CREATE TABLE intern_sub_host (
id INT NOT NULL,
main_host_id INT REFERENCES intern_host(id),
Expand All @@ -39,17 +30,16 @@ CREATE TABLE intern_sub_host (
province VARCHAR,
country VARCHAR,
other_name VARCHAR,
sub_condition INT REFERENCES intern_special_host(id),
sub_condition INT DEFAULT NULL REFERENCES intern_special_host(id),
sub_condition_date VARCHAR,
sub_approve_flag INT NOT NULL DEFAULT 2,
sub_notes VARCHAR,
PRIMARY KEY(id)
);

--be able to handle old and new sups
CREATE TABLE intern_supervisor(
id INT NOT NULL,
host_id INT REFERENCES intern_host(id),
host_id INT DEFAULT NULL REFERENCES intern_host(id),
supervisor_first_name VARCHAR NULL,
supervisor_last_name VARCHAR NULL,
supervisor_title VARCHAR NULL,
Expand All @@ -66,7 +56,6 @@ CREATE TABLE intern_supervisor(
PRIMARY KEY(id)
);

--agency_id keep for old records for now
ALTER TABLE intern_internship ADD COLUMN supervisor_id INT;
ALTER TABLE intern_internship ADD COLUMN host_id INT;
ALTER TABLE intern_internship ADD COLUMN host_sub_id INT;
Expand Down
2 changes: 1 addition & 1 deletion class/Command/HostRest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function get() {
$sql = "SELECT id, host_name, host_condition, host_approve_flag FROM intern_host WHERE host_approve_flag = 2 ORDER BY host_name ASC";
} else if(isset($_REQUEST['Condition'])){
$sql = "SELECT intern_host.id, host_name, host_condition, host_approve_flag, host_condition_date, host_notes, admin_message, intern_special_host.id AS con_id
FROM intern_host JOIN intern_special_host ON intern_host.host_condition = intern_special_host.id WHERE host_condition IS NOT NULL ORDER BY host_name ASC";
FROM intern_host LEFT JOIN intern_special_host ON intern_host.host_condition = intern_special_host.id ORDER BY host_name ASC";
} else if(isset($_REQUEST['Waiting'])){
if($_REQUEST['Waiting']){
$sql = "SELECT id, host_name, host_condition, host_approve_flag FROM intern_host WHERE host_approve_flag != 0 ORDER BY host_name ASC";
Expand Down
4 changes: 2 additions & 2 deletions class/Command/SubRest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public function get() {
if($_REQUEST['domestic']=='true'){
$Main = $_REQUEST['main'];
$State = $_REQUEST['location'];
$sql = "SELECT id, main_host_id, sub_name, sub_condition FROM intern_sub_host WHERE main_host_id = :main AND state = :state ORDER BY sub_name ASC";
$sql = "SELECT id, main_host_id, sub_name, sub_condition FROM intern_sub_host WHERE main_host_id = :main AND state = :state AND sub_approve_flag != 0 ORDER BY sub_name ASC";
$arr = array('main' => $Main, 'state'=>$State);
} else if($_REQUEST['domestic']=='false'){
$Main = $_REQUEST['main'];
$Country = $_REQUEST['location'];
$sql = "SELECT id, main_host_id, sub_name, sub_condition FROM intern_sub_host WHERE main_host_id = :main AND country = :country ORDER BY sub_name ASC";
$sql = "SELECT id, main_host_id, sub_name, sub_condition FROM intern_sub_host WHERE main_host_id = :main AND country = :country AND sub_approve_flag != 0 ORDER BY sub_name ASC";
$arr = array('main' => $Main, 'country'=>$Country);
}
} else if(isset($_REQUEST['Conditions'])){
Expand Down
4 changes: 3 additions & 1 deletion class/EditInternshipFormView.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function buildInternshipForm() {
/*********************
* Copy to Next Term *
*********************/
if($this->intern->getStateName() != 'DeniedState'){
if($this->intern->getStateName() != 'DeniedState' && \Current_User::allow('intern', 'create_internship')){
// Get next three terms
$term = TermFactory::getTermByTermCode($this->intern->getTerm());

Expand Down Expand Up @@ -164,6 +164,8 @@ public function buildInternshipForm() {
if(sizeof($this->tpl['CONTINUE_TERM_LIST']) == 0) {
$this->tpl['CONTINUE_TERM_NO_TERMS'] = 'No future terms available.';
}
} else if(!\Current_User::allow('intern', 'create_internship')){
$this->tpl['CONTINUE_TERM_NO_TERMS'] = 'You do not have permission to create new internships.';
} else{
$this->tpl['CONTINUE_TERM_NO_TERMS'] = 'No future terms available.';
}
Expand Down
8 changes: 4 additions & 4 deletions class/SubHostFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,17 @@ public static function getSubHostCond($m_host_id, $state, $country) {
if ($country == 'US') {
$stmt = $db->prepare("SELECT ish.id, ish.sub_name FROM intern_sub_host AS ish
LEFT JOIN intern_special_host AS isp ON ish.sub_condition=isp.id
WHERE ish.state=:state AND ish.main_host_id=:m_host_id
AND (ish.sub_condition IS null OR isp.stop_level<>'Stop')");
WHERE ish.state=:state AND ish.main_host_id=:m_host_id AND ish.sub_approve_flag != 0
AND (ish.sub_condition IS null OR isp.stop_level<>'Stop') ORDER BY ish.sub_name ASC");
$stmt->execute(array('state' => $state, 'm_host_id' => $m_host_id));
$stmt->setFetchMode(\PDO::FETCH_ASSOC);

$results = $stmt->fetchAll();
} else {
$stmt = $db->prepare("SELECT ish.id, ish.sub_name FROM intern_sub_host AS ish
LEFT JOIN intern_special_host AS isp ON ish.sub_condition=isp.id
WHERE ish.country=:country AND ish.main_host_id=:m_host_id
AND (ish.sub_condition IS null OR isp.stop_level<>'Stop')");
WHERE ish.country=:country AND ish.main_host_id=:m_host_id AND ish.sub_approve_flag != 0
AND (ish.sub_condition IS null OR isp.stop_level<>'Stop') ORDER BY ish.sub_name ASC");
$stmt->execute(array('country' => $country, 'm_host_id' => $m_host_id));
$stmt->setFetchMode(\PDO::FETCH_ASSOC);

Expand Down
40 changes: 18 additions & 22 deletions class/Supervisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,25 @@ public function getSupervisorFullName(){
* Get the domestic looking address of supervisor.
*/
public function getSuperAddress(){
if($this->address_same_flag == 1){
return $this->getAddress();
}else{
$add = array();
if(!empty($this->supervisor_address)){
$add[] = $this->supervisor_address . ',';
}
if(!empty($this->supervisor_city)){
$add[] = $this->supervisor_city . ',';
}
if(!empty($this->supervisor_state)){
$add[] = $this->supervisor_state;
}
if(!empty($this->supervisor_zip)){
$add[] = $this->supervisor_zip;
}

if(!empty($this->supervisor_country)){
$add[] = $this->supervisor_country;
}

return implode(' ', $add);
$add = array();
if(!empty($this->supervisor_address)){
$add[] = $this->supervisor_address . ',';
}
if(!empty($this->supervisor_city)){
$add[] = $this->supervisor_city . ',';
}
if(!empty($this->supervisor_state)){
$add[] = $this->supervisor_state;
}
if(!empty($this->supervisor_zip)){
$add[] = $this->supervisor_zip;
}

if(!empty($this->supervisor_country)){
$add[] = $this->supervisor_country;
}

return implode(' ', $add);
}

public function getId(){
Expand Down
2 changes: 1 addition & 1 deletion class/WorkflowState/CancelledState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class CancelledState extends WorkflowState {
const friendlyName = 'Cancelled';
const sortIndex = 8;
const sortIndex = 9;

public function getAllowedPermissionList(){
return array('cancel', 'reinstate');
Expand Down
2 changes: 1 addition & 1 deletion class/WorkflowState/DeanApprovedGradState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class DeanApprovedGradState extends WorkflowState {
const friendlyName = 'Dean Approved / Pending Graduate School Aproval';
const sortIndex = 10;
const sortIndex = 5;

public function getAllowedPermissionList(){
return array('grad_school_approve', 'register', 'oied_certify', 'distance_ed_register');
Expand Down
2 changes: 1 addition & 1 deletion class/WorkflowState/DeniedState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class DeniedState extends WorkflowState {
const friendlyName = 'Denied';
const sortIndex = 9;
const sortIndex = 10;

public function getAllowedPermissionList(){
return array('special_host');
Expand Down
2 changes: 1 addition & 1 deletion class/WorkflowState/GradSchoolApprovedState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class GradSchoolApprovedState extends WorkflowState {
const friendlyName = 'Graduate School Approved / Pending Registration';
const sortIndex = 5;
const sortIndex = 6;

public function getAllowedPermissionList(){
return array('grad_school_approve', 'register', 'oied_certify', 'distance_ed_register');
Expand Down
2 changes: 1 addition & 1 deletion class/WorkflowState/RegisteredState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class RegisteredState extends WorkflowState {
const friendlyName = 'Registered';
const sortIndex = 6;
const sortIndex = 7;

public function getAllowedPermissionList(){
return array('register');
Expand Down
2 changes: 1 addition & 1 deletion class/WorkflowState/RegistrationIssueState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class RegistrationIssueState extends WorkflowState {
const friendlyName = 'Registration Issue';
const sortIndex = 7;
const sortIndex = 8;

public function getAllowedPermissionList(){
return array('grad_school_approve', 'register', 'oied_certify', 'distance_ed_register');
Expand Down
2 changes: 1 addition & 1 deletion contrib/importHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function createHost($name){
if($id_result){
$id_result = pg_fetch_row($id_result);
$id = $id_result[0];
$sql = "INSERT INTO intern_host (id, host_name) VALUES ($id, '$name')";
$sql = "INSERT INTO intern_host (id, host_name, host_approve_flag) VALUES ($id, '$name', 1)";
$result = pg_query($sql);
if($result === false){
echo "failed to insert host\n\n";
Expand Down
1 change: 1 addition & 0 deletions contrib/importSubHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
$values['zip'] = $line[5];
$values['province'] = $line[6];
$values['country'] = $line[7];
$values['sub_approve_flag'] = 1;

$intern_result = createSubHost($db, $values);

Expand Down
74 changes: 74 additions & 0 deletions contrib/importUpdateIntern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/php
<?php
/**
* This file is part of Internship Inventory.
*
* Internship Inventory is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Internship Inventory is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License version 3
* along with Internship Inventory. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2011-2018 Appalachian State University
*/


require_once('cliCommon.php');
require_once('dbConnect.php');

ini_set('display_errors', 1);
ini_set('ERROR_REPORTING', E_WARNING);
error_reporting(E_ALL);

$args = array('input_file'=>'');
$switches = array();
check_args($argc, $argv, $args, $switches);

// Open input and output files
$inputFile = fopen($args['input_file'], 'r');

if($inputFile === FALSE){
die("Could not open input file.\n");
exit;
}

$db = connectToDb();

if(!$db){
die('Could not connect to database.\n');
}

// Parse CSV input into fields line by line
while(($line = fgetcsv($inputFile, 0, '|')) !== FALSE) {
foreach($line as $key=>$element){
$line[$key] = pg_escape_string($element);
}
$arrIn = $line[0];
$new = explode(',', $arrIn);
$len = count($new);
$host = $new[$len-2];
$subHost = $new[$len-1];
array_pop($new);
array_pop($new);
$internships = implode("','",$new);
$internship = "'".$internships."'";

$sql = "UPDATE intern_internship SET host_id=$host, host_sub_id=$subHost WHERE id IN ($internship)";

$result = pg_query($sql);

if($result === false){
echo $sql . "\n\n";
echo pg_last_error() . "\n\n";
}
}

pg_close($db);
fclose($inputFile);
Loading

0 comments on commit 7296b11

Please sign in to comment.