forked from alisonperez/chits
-
Notifications
You must be signed in to change notification settings - Fork 15
/
class.mysqldb.php
executable file
·160 lines (146 loc) · 6.9 KB
/
class.mysqldb.php
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
<?
class MySQLDB {
var $conn = 0;
function mysqldb () {
//
// database module
//
$this->version = "0.2";
$this->author = "Herman Tolentino MD";
if (!file_exists("../modules/_dbselect.php")) {
$this->setup("../db.xml");
}
}
function setup() {
//
// writes down _dbselect.php
//
if (func_num_args()>0) {
$arg_list = func_get_args();
$filename = $arg_list[0];
}
if (file_exists($filename)) {
$db = $this->readconfig($filename);
foreach ($db as $key=>$dbname) {
foreach($dbname as $key=>$value) {
//print $value;
$_SESSION[$key] = $value;
}
}
if ($fp = @fopen("../modules/_dbselect.php", "w+")) {
$dbfile .= "<?php\n";
$dbfile .= "\$_SESSION[\"dbname\"] = \"".$_SESSION["dbname"]."\";\n";
$dbfile .= "\$_SESSION[\"dbuser\"] = \"".$_SESSION["dbuser"]."\";\n";
$dbfile .= "\$_SESSION[\"dbpass\"] = \"".$_SESSION["dbpass"]."\";\n";
$dbfile .= "\$conn = mysql_connect(\"".$_SESSION["dbhost"]."\", \"".$_SESSION["dbuser"]."\", \"".$_SESSION["dbpass"]."\");\n";
$dbfile .= "\$db->connectdb(\"".$_SESSION["dbname"]."\");\n";
$dbfile .= "?>";
if (fwrite($fp, $dbfile)) {
fclose($fp);
}
}
}
}
function connectdb() {
if (func_num_args()>0) {
$arg_list = func_get_args();
$dbname = $arg_list[0];
}
//$self->conn = mysql_connect($_SESSION["dbhost"], $_SESSION["dbuser"], $_SESSION["dbpass"]) or die(mysql_errno().": ".mysql_error());
if (!mysql_select_db($dbname)) {
$this->create_system_tables($dbname);
module::set_lang("LBL_NAVIGATION", "english", "NAVIGATION", "Y");
module::set_lang("LBL_HOME", "english", "HOME", "Y");
module::set_lang("LBL_SIGN_IN", "english", "SIGN IN", "Y");
module::set_lang("LBL_LOGIN_NAME", "english", "LOGIN NAME", "Y");
module::set_lang("LBL_PASSWORD", "english", "PASSWORD", "Y");
module::set_lang("LBL_SIGN_OUT", "english", "SIGN OUT", "Y");
module::set_lang("BTN_SIGN_OUT", "english", "SIGN OUT", "Y");
module::set_lang("MENU_PATIENTS", "english", "PATIENTS", "Y");
module::set_lang("BTN_SIGN_OUT", "english", "SIGN OUT", "Y");
module::set_lang("MENU_ABOUT", "english", "ABOUT", "Y");
module::set_lang("MENU_HOWTO", "english", "HOWTO", "Y");
module::set_lang("MENU_CREDITS", "english", "CREDITS", "Y");
module::set_lang("FTITLE_SITE_USER_FORM", "english", "SITE USER FORM", "Y");
module::set_lang("FTITLE_SITE_USERS", "english", "SITE USERS", "Y");
module::set_lang("LBL_FIRST_NAME", "english", "FIRST NAME", "Y");
module::set_lang("LBL_MIDDLE_NAME", "english", "MIDDLE NAME", "Y");
module::set_lang("LBL_LAST_NAME", "english", "LAST NAME", "Y");
module::set_lang("LBL_LAST_NAME", "english", "LAST NAME", "Y");
module::set_lang("LBL_DATE_OF_BIRTH", "english", "BIRTH DATE", "Y");
module::set_lang("LBL_GENDER", "english", "GENDER", "Y");
module::set_lang("LBL_PIN", "english", "4-NUMBER PIN", "Y");
module::set_lang("LBL_ROLE", "english", "ROLE", "Y");
module::set_lang("LBL_LANGUAGE_DIALECT", "english", "LANGUAGE/DIALECT", "Y");
module::set_lang("LBL_CONFIRM_PASSWORD_AGAIN", "english", "CONFIRM PASSWORD BY TYPING AGAIN", "Y");
module::set_lang("LBL_ACTIVE_USER", "english", "ACTIVE ACCOUNT", "Y");
module::set_lang("LBL_ADMIN_USER", "english", "ADMIN USER", "Y");
module::set_lang("LBL_EMAIL", "english", "EMAIL ACCOUNT", "Y");
module::set_lang("LBL_CELLULAR", "english", "CELLULAR PHONE", "Y");
module::set_lang("FTITLE_ROLE_FORM", "english", "ROLE FORM", "Y");
module::set_lang("LBL_ROLE_ID", "english", "ROLE ID", "Y");
module::set_lang("LBL_ROLE_NAME", "english", "ROLE NAME", "Y");
module::set_lang("FTITLE_ROLE_LIST", "english", "ROLE LIST", "Y");
module::set_lang("THEAD_NAME", "english", "NAME", "Y");
module::set_lang("FTITLE_LOCATION_FORM", "english", "LOCATION", "Y");
module::set_lang("INSTR_ROLE_FORM", "english", "<b>INSTRUCTIONS: After creating users, be sure to set data permissions under <b>MODULES->Data Access By Roles</b>.</b>", "Y");
module::set_lang("INSTR_LOCATION_FORM", "english", "<b>INSTRUCTIONS: After creating users, be sure to set permissions for the modules and menu items under <b>MODULES->Menu Locations</b>.</b>", "Y");
module::set_lang("LBL_LOCATION_ID", "english", "LOCATION ID", "Y");
module::set_lang("LBL_LOCATION_NAME", "english", "LOCATION NAME", "Y");
module::set_lang("FTITLE_LOCATION_LIST", "english", "LOCATION LIST", "Y");
module::set_lang("LBL_REGISTERED_BY", "english", "REGISTERED BY", "Y");
}
}
function selectdb ($db) {
mysql_select_db("$db");
}
function connid () {
return $self->conn;
}
function create_system_tables() {
//
// create system tables if not present
//
if (func_num_args()>0) {
$arg_list = func_get_args();
$dbname = $arg_list[0];
}
mysql_query("CREATE DATABASE `$dbname`;") or die(mysql_errno().": ".mysql_error());
mysql_select_db($dbname);
module::load_sql("setup.sql");
}
function parseXML($mvalues) {
for ($i=0; $i < count($mvalues); $i++)
$node[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
return ($node);
}
function readconfig($filename) {
// read the xml database
$data = implode("",file($filename));
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$data,$values,$tags);
xml_parser_free($parser);
// loop through the structures
foreach ($tags as $key=>$val) {
if ($key == "db") {
$noderanges = $val;
// each contiguous pair of array entries are the
// lower and upper range for each node definition
for ($i=0; $i < count($noderanges); $i+=2) {
$offset = $noderanges[$i] + 1;
$len = $noderanges[$i + 1] - $offset;
$tdb[] = $this->parseXML(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
}
function backup_database() {
}
// end of class
}
?>