aboutsummaryrefslogtreecommitdiff
path: root/admin/admin_functions.php
blob: e0583423167ca75a60b55b3b4775d74c08b94215 (plain) (blame)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
 * Bayonet Content Management System
 * Copyright (C) 2008-2011  Joseph Hunkeler & Evan O'Connell
 *
 * This program 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.
 *
 * This program 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
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
if(!defined("ADMIN_FILE"))
{
  die("Access denied.");
  return;
}

function is_loggedin()
{
  $id = session_id();
  if($id == "")
  {
    header("location: index.php");
    return false;
  }
  return true;
}

function login()
{
  global $db;
  
  if(isset($_SESSION['username']) || isset($_SESSION['password']))
  {
    return true;
  }
  
  if(isset($_POST['processed']))
  {
    $username = addslashes($_POST['username']);
    $password = addslashes($_POST['password']);
    $password = crypt(md5($password),'iamnotadirtywhorebitch');
    $result = $db->Query("SELECT * FROM bayonet_users WHERE username = '$username' AND password = '$password' LIMIT 1");
    $rows = $db->Rows($result);
    $row = $db->FetchRow($result);

    if($rows > 0)
    {
      $_SESSION['username'] = stripslashes($username);
      $_SESSION['password'] = stripslashes($password);
      $_SESSION['level'] = $row['level'];
      return true;
    }
    else
    {
      ReportError("Login incorrect.");
      
	  //NOT CORRECT LOGIN, DEFAULT TO LOGIN PAGE
      //echo "<meta http-equiv=\"Refresh\" content=\"1;url=index.php\">";
      PageRedirect(1, "index.php");
      
      return false;
    }
    
  }
  else
  {
    echo "<form action=\"\" method=\"post\">\n";
    //OpenTable();
    echo "<table style=\"width:100%; height:600px;\">";
      echo "<tr><td><table width=\"450px\" style=\"background-color:white;\" align=\"center\">\n
      <tr><td colspan=\"2\" style=\"text-align:center;\"><img src=\"images/bayonet_logo.jpg\" /></td></tr>\n
      <tr><th colspan=\"2\">Administrative Login</th></tr>\n
      <tr><th style=\"text-align:right;\">Username</th><td><input size=\"20\" type=\"text\" name=\"username\"></td></tr>\n
      <tr><th style=\"text-align:right;\">Password</th><td><input size=\"20\" type=\"password\" name=\"password\"></td></tr>\n
      <tr><th colspan=\"2\" align=\"center\"><input type=\"Submit\" name=\"processed\" value=\"Login\"></th></tr></td></tr>\n
      </table>\n";
    //CloseTable();
    echo "</table>";
    echo "</form>\n";
    return false;
  }
}

function logout()
{
  session_unset();
  session_destroy();
  
  echo "<script>location.href=\"index.php\";</script>";
}

/**
 * CompileAdmin()
 *
 *  because we want to have a horizontal display of options, we need to have
 *  the data separated by arrays.  the data is processed into single tables, and is
 *  echoed in realtime.  we checked to make sure they were arrays, but there is no
 *  checking to make sure the data passed is not malicious in nature.
 *  
 * @param mixed $head
 * @param mixed $body
 * @return
 */
function CompileAdmin($head,$body)
{
  /*if we were not passed arrays, then say goodbye*/
  if(!is_array($head) || !is_array($body))
  {
    echo "must be array\n";
    return;
  }  
  
  echo "<table class=\"cleartable\" width=\"100%\">";

$num = 1;
  foreach($body as $td)
  {
  	if($num==1){
  		echo "<tr style=\"text-align:center; height:90px;\">";	
  	}
    echo "<td class=\"center\" style=\"width:12%;\">$td</td>\n";
    if($num%8 == 0){
    	echo "</tr>";
		$num=0;  
    }
    $num++;
  }

  if($num == 1)
  	echo "</table>\n";
  else
  	echo "</tr></table>\n";
}

/**
 * OpenTable()
 *
 *  The administration OpenTable() function requires an argument to define
 *  the header title. It may be wise to replace the standard OpenTable() function
 *  with this one...  that's alot of code to unfuck though. 
 * 
 * @param mixed $title
 * @return
 */
function OpenTable_Ex($title)
{
  echo "<table align=\"center\"><tr><th>{$title}</th></tr><tr><td>";
}

/**
 * CloseTable()
 * 
 * @return
 */
function CloseTable_Ex()
{
  echo "</td></tr></table>";
}

?>