This repository was archived by the owner on Feb 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposition_check.php
More file actions
97 lines (77 loc) · 2.33 KB
/
position_check.php
File metadata and controls
97 lines (77 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
require_once('conn.php');
//Check to see if the user can see MD tools
function MD_check(){
if(!isset($_SESSION['positionID']) || empty($_SESSION['positionID']))
return false;
else
$positionID = $_SESSION['positionID'];
$valid_positions = array(0,1,2,3,8,13,14,17,18,19,20);
foreach($valid_positions as $pos)
if(in_array($pos, $positionID))
return true;
return false;
}
function engineerCheck($positionID){
$valid_positions = array(1,8,10,6,5);
foreach($valid_positions as $pos)
if(in_array($pos, $positionID))
return true;
return false;
}
/**
* positionCheck($valid_positions)
* Checks to see whether the current user has rights as dictated by position name given
*
* @author David A. Cohen, II.
*
*/
function positionCheck($valid_positions){
if(is_array($valid_positions)){
// check each position, returning at the first valid one
foreach($valid_positions as $pos)
if(positionIDCheck(getPositionIDFor($pos)))
return true;
// else invalid position
return false;
}
else if($valid_positions == "seniorstaff")
return positionIDCheck(array(0,1,2,3,4,5,6,7,8));
}
function positionIDCheck($valid_positions){
// check session
$result = false;
if(!empty($_SESSION['positionID'])){
$positionID = $_SESSION['positionID'];
if(is_array($valid_positions)){
foreach($valid_positions as $pos)
if(in_array($pos, $positionID))
$result = true;
}
else if($valid_positions == $positionID)
$result = true;
}
return $result;
}
/**
* Returns the positionID for a given position name, or -1 if not found in database
* @author David A. Cohen, II.
* @param string $position The name of the position to be checked (i.e. "Computer Engineer")
* @return int The correspoinding positionID
*/
function getPositionIDFor($position){
$q = sprintf("SELECT positionID FROM `def_positions` WHERE position LIKE '%s' LIMIT 1", mysql_real_escape_string($position));
$res = mysql_query($q) or die("MySQL error [". __FILE__ ."] near line" . __LINE__ . ": " .mysql_error());
if(mysql_num_rows($res) == 0)
$result = -1;
else{
$row = mysql_fetch_assoc($res);
$result = $row['positionID'];
}
return($result);
}
// check if user is eligible to write a review
function reviewCheck(){
return($_SESSION['statusID'] == 0 || $_SESSION['statusID'] == 1 || $_SESSION['statusID'] == 5);
}
?>