Skip to content

Commit 95a2532

Browse files
author
flx5
committed
- Added MySQL
- Fixed Bug in JS (Ajax/Reload)
1 parent 24317c2 commit 95a2532

19 files changed

+1028
-215
lines changed

.htaccess

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Order Deny,Allow
2-
Allow from all
2+
Allow from all
3+

inc/api.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ public function plan_update($return = false) {
175175
$p = new parse();
176176

177177
foreach ($files as $file) {
178+
179+
if($file == "")
180+
continue;
181+
178182
$file = utf8_decode($file);
179183
$file = substr($file, strpos($file, "<html>"));
180184
$p->parseHTML($file);
@@ -241,7 +245,7 @@ public function replacements($return = false) {
241245
}
242246
}
243247
}
244-
248+
245249
if ($return)
246250
return $output;
247251

inc/db/MySQL.php

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
<?php
2+
3+
/* =================================================================================*\
4+
|* This file is part of InMaFSS *|
5+
|* InMaFSS - INformation MAnagement for School Systems - Keep yourself up to date! *|
6+
|* ############################################################################### *|
7+
|* Copyright (C) flx5 *|
8+
|* E-Mail: [email protected] *|
9+
|* ############################################################################### *|
10+
|* InMaFSS is free software; you can redistribute it and/or modify *|
11+
|* it under the terms of the GNU Affero General Public License as published by *|
12+
|* the Free Software Foundation; either version 3 of the License, *|
13+
|* or (at your option) any later version. *|
14+
|* ############################################################################### *|
15+
|* InMaFSS is distributed in the hope that it will be useful, *|
16+
|* but WITHOUT ANY WARRANTY; without even the implied warranty of *|
17+
|* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *|
18+
|* See the GNU Affero General Public License for more details. *|
19+
|* ############################################################################### *|
20+
|* You should have received a copy of the GNU Affero General Public License *|
21+
|* along with InMaFSS; if not, see http://www.gnu.org/licenses/. *|
22+
\*================================================================================= */
23+
24+
class _MySQL extends SQL {
25+
26+
private $connected = false;
27+
private $hostname = "localhost";
28+
private $username = "root";
29+
private $password = "pass";
30+
private $database = "inmafss";
31+
private $link;
32+
private $count = 0;
33+
private $requests = Array();
34+
35+
public function __construct($host, $user, $pass, $db) {
36+
$this->connected = false;
37+
$this->hostname = $host;
38+
$this->username = $user;
39+
$this->password = $pass;
40+
$this->database = $db;
41+
}
42+
43+
public function IsConnected() {
44+
if ($this->connected) {
45+
return true;
46+
}
47+
48+
return false;
49+
}
50+
51+
public function Connect() {
52+
$this->link = @mysql_connect($this->hostname, $this->username, $this->password);
53+
54+
if($this->link === false) {
55+
$this->Error('Connect Error (' . mysql_errno() . ') ' . mysql_error());
56+
return;
57+
}
58+
59+
$selectDB = @mysql_select_db($this->database, $this->link);
60+
61+
if($selectDB === false) {
62+
$this->Error('Connect Error (' . mysql_errno($this->link) . ') ' . mysql_error($this->link));
63+
return;
64+
}
65+
66+
$this->connected = true;
67+
}
68+
69+
public function Disconnect() {
70+
if ($this->connected) {
71+
mysql_close($this->link) or $this->error("could not close conn");
72+
$this->connected = false;
73+
}
74+
}
75+
76+
public function DoQuery($query) {
77+
$this->requests[] = $query;
78+
$resultset = mysql_query($query, $this->link) or $this->error($this->link->error);
79+
80+
if ($resultset === true)
81+
return true;
82+
83+
if ($resultset === false)
84+
return false;
85+
86+
return new _MYSQL_Result($resultset);
87+
}
88+
89+
public function insertID() {
90+
return mysql_insert_id($this->link);
91+
}
92+
93+
public function affected_rows() {
94+
return mysql_affected_rows($this->link);
95+
}
96+
97+
public function real_escape_string($strInput = '') {
98+
return mysql_real_escape_string($strInput, $this->link);
99+
}
100+
101+
public function __destruct() {
102+
$this->disconnect();
103+
}
104+
105+
public function GetCount() {
106+
return count($this->requests);
107+
}
108+
109+
public function GetRequests() {
110+
return $this->requests;
111+
}
112+
113+
public function getErrorList() {
114+
return null;
115+
}
116+
117+
public function getFieldsInfo($table) {
118+
$sql = dbquery("SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COLUMN_TYPE FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='" . config("dbname") . "' AND `TABLE_NAME`='" . $table . "';");
119+
120+
$info = Array();
121+
while ($field = $sql->fetchObject()) {
122+
$info[$field->COLUMN_NAME] = Array(
123+
'name' => $field->COLUMN_NAME,
124+
'type' => $field->DATA_TYPE,
125+
'max_length' => $field->CHARACTER_MAXIMUM_LENGTH,
126+
);
127+
128+
if($field->DATA_TYPE == 'enum') {
129+
$info[$field->COLUMN_NAME]['enum'] = explode(",", str_replace("'", "", substr($field->COLUMN_TYPE, 5, (strlen($field->COLUMN_TYPE)-6))));
130+
}
131+
}
132+
133+
return $info;
134+
}
135+
136+
}
137+
138+
class _MYSQL_Result {
139+
140+
private $res;
141+
142+
public function __construct($result) {
143+
$this->res = $result;
144+
}
145+
146+
public function count() {
147+
return mysql_num_rows($this->res);
148+
}
149+
150+
public function fetchAssoc() {
151+
$ret = mysql_fetch_assoc($this->res);
152+
return $ret;
153+
}
154+
155+
public function fetchArray() {
156+
$ret = mysql_fetch_array($this->res);
157+
return $ret;
158+
}
159+
160+
public function fetchObject() {
161+
return mysql_fetch_object($this->res);
162+
}
163+
164+
public function fetchRow() {
165+
return mysql_fetch_row($this->res);
166+
}
167+
168+
function result($row = 0, $field = 0) {
169+
mysql_data_seek($this->res, $row);
170+
$datarow = mysql_fetch_array($this->res);
171+
return $datarow[$field];
172+
}
173+
174+
function fetchFieldByName($columnName) {
175+
$fields = $this->fetchFields($this->res);
176+
foreach ($fields as $field) {
177+
if ($field->name == $columnName)
178+
return $field;
179+
}
180+
181+
return null;
182+
}
183+
184+
function fetchFields() {
185+
$fields = Array();
186+
187+
while($field = mysql_fetch_fields($this->res))
188+
$fields[] = $field;
189+
190+
return $fields;
191+
}
192+
193+
public function close() {
194+
}
195+
196+
public function __destruct() {
197+
}
198+
199+
// Easy access to parent function
200+
public function getErrorList() {
201+
return getVar("sql")->getErrorList();
202+
}
203+
204+
}
205+
206+
?>

inc/db/MySQLI.php

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class _MySQLI extends SQL {
2727
private $hostname = "localhost";
2828
private $username = "root";
2929
private $password = "pass";
30-
private $database = "uberdb";
30+
private $database = "inmafss";
3131
private $link;
3232
private $count = 0;
3333
private $requests = Array();
@@ -38,39 +38,6 @@ public function __construct($host, $user, $pass, $db) {
3838
$this->username = $user;
3939
$this->password = $pass;
4040
$this->database = $db;
41-
42-
$this->setConstants();
43-
}
44-
45-
private function setConstants() {
46-
define('DB_TYPE_DECIMAL', MYSQLI_TYPE_DECIMAL);
47-
define('DB_TYPE_NEWDECIMAL', MYSQLI_TYPE_NEWDECIMAL);
48-
define('DB_TYPE_BIT', MYSQLI_TYPE_BIT);
49-
define('DB_TYPE_TINY', MYSQLI_TYPE_TINY);
50-
define('DB_TYPE_SHORT', MYSQLI_TYPE_SHORT);
51-
define('DB_TYPE_LONG', MYSQLI_TYPE_LONG);
52-
define('DB_TYPE_FLOAT', MYSQLI_TYPE_FLOAT);
53-
define('DB_TYPE_DOUBLE', MYSQLI_TYPE_DOUBLE);
54-
define('DB_TYPE_NULL', MYSQLI_TYPE_NULL);
55-
define('DB_TYPE_TIMESTAMP', MYSQLI_TYPE_TIMESTAMP);
56-
define('DB_TYPE_LONGLONG', MYSQLI_TYPE_LONGLONG);
57-
define('DB_TYPE_INT24', MYSQLI_TYPE_INT24);
58-
define('DB_TYPE_DATE', MYSQLI_TYPE_DATE);
59-
define('DB_TYPE_TIME', MYSQLI_TYPE_TIME);
60-
define('DB_TYPE_DATETIME', MYSQLI_TYPE_DATETIME);
61-
define('DB_TYPE_YEAR', MYSQLI_TYPE_YEAR);
62-
define('DB_TYPE_NEWDATE', MYSQLI_TYPE_NEWDATE);
63-
define('DB_TYPE_INTERVAL', MYSQLI_TYPE_INTERVAL);
64-
define('DB_TYPE_ENUM', MYSQLI_TYPE_ENUM);
65-
define('DB_TYPE_SET', MYSQLI_TYPE_SET);
66-
define('DB_TYPE_TINY_BLOB', MYSQLI_TYPE_TINY_BLOB);
67-
define('DB_TYPE_MEDIUM_BLOB', MYSQLI_TYPE_MEDIUM_BLOB);
68-
define('DB_TYPE_LONG_BLOB', MYSQLI_TYPE_LONG_BLOB);
69-
define('DB_TYPE_BLOB', MYSQLI_TYPE_BLOB);
70-
define('DB_TYPE_VAR_STRING', MYSQLI_TYPE_VAR_STRING);
71-
define('DB_TYPE_STRING', MYSQLI_TYPE_STRING);
72-
define('DB_TYPE_CHAR', MYSQLI_TYPE_CHAR);
73-
define('DB_TYPE_GEOMETRY', MYSQLI_TYPE_GEOMETRY);
7441
}
7542

7643
public function IsConnected() {

inc/parse.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class parse {
3030
var $supervisor = Array();
3131

3232
function parseHTML($html) {
33+
34+
if($html == "")
35+
return;
36+
3337
$html = html_entity_decode($html);
3438
$html = preg_replace("#\r\n#","\n",$html);
3539

inc/parse/willi2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ function parseHTML($html) {
3232

3333
function parsePupilHTML($html) {
3434
$date = substr($html, strpos($html, 'Vertretungsplan ') + strlen('Vertretungsplan '), strpos($html, ')') - strpos($html, 'Vertretungsplan '));
35-
$date = substr($date, strpos($date, ','));
36-
$date = explode("-", $date);
35+
$date = substr($date, strpos($date, ','));
36+
$date = explode("-", $date);
3737

3838
$time = trim(substr($date[1], 0, strpos($date[1], ")")));
3939
$time = explode(":", $time);

inc/sql.php

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -44,69 +44,6 @@ public static function GenerateInstance($type, $host, $user, $pass, $db) {
4444

4545
return new $type($host, $user, $pass, $db);
4646
}
47-
48-
public static function GetType($typeId) {
49-
switch ($typeId) {
50-
case DB_TYPE_DECIMAL:
51-
return 'DECIMAL';
52-
case DB_TYPE_NEWDECIMAL:
53-
return 'NEWDECIMAL';
54-
case DB_TYPE_BIT:
55-
return 'BIT';
56-
case DB_TYPE_TINY:
57-
return 'TINY';
58-
case DB_TYPE_SHORT:
59-
return 'SHORT';
60-
case DB_TYPE_LONG:
61-
return 'LONG';
62-
case DB_TYPE_FLOAT:
63-
return 'FLOAT';
64-
case DB_TYPE_DOUBLE:
65-
return 'DOUBLE';
66-
case DB_TYPE_NULL:
67-
return 'NULL';
68-
case DB_TYPE_TIMESTAMP:
69-
return 'TIMESTAMP';
70-
case DB_TYPE_LONGLONG:
71-
return 'LONGLONG';
72-
case DB_TYPE_INT24:
73-
return 'INT24';
74-
case DB_TYPE_DATE:
75-
return 'DATE';
76-
case DB_TYPE_TIME:
77-
return 'TIME';
78-
case DB_TYPE_DATETIME:
79-
return 'DATETIME';
80-
case DB_TYPE_YEAR:
81-
return 'YEAR';
82-
case DB_TYPE_NEWDATE:
83-
return 'NEWDATE';
84-
case DB_TYPE_INTERVAL:
85-
return 'INTERVAL';
86-
case DB_TYPE_ENUM:
87-
return 'ENUM';
88-
case DB_TYPE_SET:
89-
return 'SET';
90-
case DB_TYPE_TINY_BLOB:
91-
return 'BLOB';
92-
case DB_TYPE_MEDIUM_BLOB:
93-
return 'BLOB';
94-
case DB_TYPE_LONG_BLOB:
95-
return 'BLOB';
96-
case DB_TYPE_BLOB:
97-
return 'BLOB';
98-
case DB_TYPE_VAR_STRING:
99-
return 'STRING';
100-
case DB_TYPE_STRING:
101-
return 'STRING';
102-
case DB_TYPE_CHAR:
103-
return 'CHAR';
104-
case DB_TYPE_GEOMETRY:
105-
return 'GEOMETRY';
106-
default:
107-
return 'UNKNOWN';
108-
}
109-
}
11047
}
11148

11249
?>

inc/tpl/api_edit.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $permissionsAvail = Array(
7171
$permissions = implode("|", $permissions);
7272

7373
if (isset($_GET['new'])) {
74-
dbquery("INSERT INTO api (name, apikey, permissions) VALUES ('" . $name . "', '" . $apikey . "', '')");
74+
dbquery("INSERT INTO api (name, apikey, permissions) VALUES ('" . $name . "', '" . $apikey . "', '" . $permissions . "')");
7575
$_SESSION['api_add_success'] = true;
7676
header("Location: ?id=" . getVar("sql")->insertID());
7777
exit;
@@ -87,7 +87,7 @@ $permissionsAvail = Array(
8787
}
8888

8989
if (isset($_GET['new']) && !isset($_POST['caption'])) {
90-
$data = Array('name' => '', 'apikey' => GenerateAPI());
90+
$data = Array('name' => '', 'apikey' => GenerateAPI(), 'permissions'=>'');
9191
} else {
9292
$sql = dbquery("SELECT * FROM api WHERE id = " . $id);
9393
$data = $sql->fetchAssoc();

0 commit comments

Comments
 (0)