PhpLabWare version 0.3 
/dd/ -> 0_001_inc.php

1  <?php
2 
3  // 0_001_inc.php - initial database definition
4  // 0_001_inc.php - author: Nico Stuurman <nicost@sourceforge.net>
5  // TABLES: settings authmethods users groups usersxgroups dateformats tableoftables files
6    /***************************************************************************
7    * Copyright (c) 2001 by Nico Stuurman *
8    * ------------------------------------------------------------------------ *
9    * Creates tables settings,user,groups,userxgroups and inserts initial *
10    * values. *
11    * *
12    * This program is free software; you can redistribute it and/or modify it *
13    * under the terms of the GNU General Public License as published by the *
14    * Free Software Foundation; either version 2 of the License, or (at your *
15    * option) any later version. *
16    \**************************************************************************/
17    
18    
19     $test=true;
20     $result=$db->Execute("CREATE TABLE settings
21          (id int PRIMARY KEY,
22          version float(8),
23          settings text,
24          created datetime)");
25     if (!$result) $test=false;
26     $result=$db->Execute("INSERT INTO settings VALUES (1,0.001,'',".$db->DBDate(time()).")");
27     if (!$result) $test=false;
28     $query="CREATE TABLE authmethods
29        (id int PRIMARY KEY,
30         sortkey int,
31         method text)";
32     if (!$db->Execute($query)) $test=false;
33     $query="INSERT INTO authmethods VALUES (1,10,'SQL')";
34     if (!$db->Execute($query)) $test=false;
35     $query="INSERT INTO authmethods VALUES (2,40,'PAM')";
36     if (!$db->Execute($query)) $test=false;
37     $query="CREATE TABLE dateformats
38          (id int PRIMARY KEY,
39           sortkey int,
40           dateformat text)";
41     if (!$db->Execute($query)) $test=false;
42     $query="INSERT INTO dateformats VALUES (1,100,'m-d-Y')";
43     if (!$db->Execute($query)) $test=false;
44     $query="INSERT INTO dateformats VALUES (2,200,'M-D-Y')";
45     if (!$db->Execute($query)) $test=false;
46     $query="INSERT INTO dateformats VALUES (3,300,'d-m-Y')";
47     if (!$db->Execute($query)) $test=false;
48     $query="INSERT INTO dateformats VALUES (4,400,'D-M-Y')";
49     if (!$db->Execute($query)) $test=false;
50     $result=$db->Execute("CREATE TABLE users
51          (id int PRIMARY KEY,
52          firstname text,
53          lastname text,
54          login text,
55          groupid int,
56          pwd text,
57          email text,
58          permissions int,
59          settings text,
60          indir text,
61          outdir text)");
62     if (!$result) $test=false;
63     $db->Execute("CREATE INDEX users_id_index ON users (id)");
64     $db->Execute("CREATE INDEX users_groupid_index ON users (groupid)");
65     $db->Execute("CREATE INDEX users_login_index ON users (login)");
66     $db->Execute("CREATE INDEX users_login_index ON users (login(10))");
67     $db->Execute("CREATE INDEX users_pwd_index ON users (pwd)");
68     $db->Execute("CREATE INDEX users_pwd_index ON users (pwd(10))");
69     $result=$db->Execute("CREATE TABLE groups
70          (id int PRIMARY KEY,
71          name text,
72          description text)");
73     if (!$result) $test=false;
74     $db->Execute("CREATE INDEX groups_id_index ON groups (id)");
75 
76     $result=$db->Execute("CREATE TABLE usersxgroups
77          (usersid int,
78          groupsid int)");
79     if (!$result) $test=false;
80 
81     $result=$db->Execute("CREATE TABLE files
82          (id int PRIMARY KEY,
83           filename text,
84           tablesfk int,
85           ftableid int,
86           mime text,
87           notes text,
88           size numeric(16),
89           title text)");
90     if (!$result) $test=false;
91     $db->Execute("CREATE INDEX files_id_index ON files (id)");
92 
93     $result=$db->Execute("CREATE TABLE tableoftables
94           (id int PRIMARY KEY,
95            sortkey int,
96            tablename text,
97            shortname text)");
98     if (!$result) $test=false;
99     $db->Execute("CREATE INDEX tables_id_index ON tableoftables (id)");
100     $db->Execute("CREATE INDEX tables_tablename_index ON tableoftables (tablename)");
101     $db->Execute("CREATE INDEX tables_tablename_index ON tableoftables (tablename(10))");
102 
103     // insert sysadmin and admin group
104     $pass= md5($pwd);
105     $id=$db->GenID("users_id_seq");
106     $idg=$db->GenID("groups_id_seq");
107     if (!($id && $idg)) $test=false;
108     $result=$db->Execute("INSERT INTO groups VALUES
109          ($idg, 'admins', 'Only for real important people')");
110     if (!$result) $test=false;
111     // default to the new menu style for all users
112     $user_settings["menustyle"]=1;
113     $user_settings=serialize($user_settings);
114     $result=$db->Execute("INSERT INTO users VALUES
115          ($id, '','sysadmin','sysadmin', $idg, '$pass','', 127, '$user_settings', '', '')");
116     if (!$result) $test=false;
117     // insert guest and guest group
118     $pass= md5("guest");
119     $id = $db->GenID("users_id_seq");
120     $idg=$db->GenID("groups_id_seq");
121     if (!($id && $idg)) $test=false;
122     $result=$db->Execute("INSERT INTO groups VALUES
123          ($idg, 'guests', 'Only for our guests')");
124     if (!$result) $test=false;
125     $result=$db->Execute("INSERT INTO users VALUES
126          ($id, '','guest','guest', $idg, '$pass','', 3, '$user_settings','','')");
127     if (!$result) $test=false;
128     $idg=$db->GenID("groups_id_seq");
129     $result=$db->Execute("INSERT INTO groups VALUES
130          ($idg, 'users', 'That is us')");
131     if (!$result) $test=false;
132     if (!$test) {
133        echo "<h3 align='center'>Problems creating database tables!\n";
134        echo "Some function might not work.</h3>\n";
135     }
136     else {
137        $version=0.001;
138     }
139     
140  ?>


Generated: Sun Oct 5 21:17:35 2003 SourceForge Logo Generated by PHPXref 0.2