Browse code

Webapps implementiert

git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@843 87cf0b9e-d624-0410-a070-f6ee81989793

bernd authored on08/12/2007 16:24:53
Showing3 changed files
... ...
@@ -97,6 +97,12 @@ elseif ($vhost['is_svn'])
97 97
 elseif ($vhost['is_webapp'])
98 98
   $vhost_type = 'webapp';
99 99
 
100
+$applist = list_available_webapps();
101
+$webapp_options = '';
102
+foreach ($applist as $app)
103
+  $webapp_options .= "<option value=\"{$app['id']}\">{$app['displayname']}</option>\n";
104
+
105
+
100 106
 $form = "
101 107
 <h4 style=\"margin-top: 2em;\">Name des VHost</h4>
102 108
     <div style=\"margin-left: 2em;\"><input type=\"text\" name=\"hostname\" id=\"hostname\" size=\"10\" value=\"{$vhost['hostname']}\" onchange=\"defaultDocumentRoot()\" /><strong>.</strong>".domainselect($vhost['domain_id'], 'onchange="defaultDocumentRoot()"');
... ...
@@ -125,7 +131,7 @@ $form .= "<br /><input type=\"checkbox\" name=\"options[]\" id=\"aliaswww\" valu
125 131
   <h4>Optionen</h4>
126 132
   <h5>Anwendung</h5>
127 133
   <select name=\"webapp\" id=\"webapp\" size=\"1\">
128
-    <option value=\"1\">Drupal 5.x</option>
134
+    {$webapp_options}
129 135
   </select>
130 136
 </div>
131 137
 
... ...
@@ -134,9 +140,7 @@ $form .= "<br /><input type=\"checkbox\" name=\"options[]\" id=\"aliaswww\" valu
134 140
 	  <input class=\"usageoption\" onclick=\"showAppropriateLines()\" type=\"radio\" name=\"vhost_type\" id=\"vhost_type_regular\" value=\"regular\" ".(($vhost_type=='regular') ? 'checked="checked" ' : '')."/><label for=\"vhost_type_regular\">&#160;Normal (selbst Dateien hinterlegen)</label><br />
135 141
 	  <input class=\"usageoption\" onclick=\"showAppropriateLines()\" type=\"radio\" name=\"vhost_type\" id=\"vhost_type_dav\" value=\"dav\" ".(($vhost_type=='dav') ? 'checked="checked" ' : '')."/><label for=\"vhost_type_dav\">&#160;WebDAV</label><br />
136 142
 	  <input class=\"usageoption\" onclick=\"showAppropriateLines()\" type=\"radio\" name=\"vhost_type\" id=\"vhost_type_svn\" value=\"svn\" ".(($vhost_type=='svn') ? 'checked="checked" ' : '')."/><label for=\"vhost_type_svn\">&#160;Subversion-Server</label><br />
137
-	  <div style=\"display: none\">
138
-	    <input class=\"usageoption\" onclick=\"showAppropriateLines()\" type=\"radio\" name=\"vhost_type\" id=\"vhost_type_webapp\" value=\"webapp\" ".(($vhost_type=='webapp') ? 'checked="checked" ' : '')."/><label for=\"vhost_type_webapp\">&#160;Eine vorgefertigte Applikation nutzen</label>
139
-	  </div>
143
+	  <input class=\"usageoption\" onclick=\"showAppropriateLines()\" type=\"radio\" name=\"vhost_type\" id=\"vhost_type_webapp\" value=\"webapp\" ".(($vhost_type=='webapp') ? 'checked="checked" ' : '')."/><label for=\"vhost_type_webapp\">&#160;Eine vorgefertigte Applikation nutzen</label>
140 144
 	</div>
141 145
 <br />
142 146
 </div>
... ...
@@ -33,6 +33,7 @@ function empty_vhost()
33 33
   $vhost['is_dav'] = 0;
34 34
   $vhost['is_svn'] = 0;
35 35
   $vhost['is_webapp'] = 0;
36
+  $vhsot['webapp_id'] = NULL;
36 37
     
37 38
   $vhost['options'] = '';
38 39
   return $vhost;
... ...
@@ -115,6 +116,16 @@ function get_all_aliases($vhost)
115 116
 }
116 117
 
117 118
 
119
+function list_available_webapps()
120
+{
121
+  $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
122
+  $ret = array();
123
+  while ($item = mysql_fetch_assoc($result))
124
+    array_push($ret, $item);
125
+  return $ret;
126
+}
127
+
128
+
118 129
 function delete_vhost($id)
119 130
 {
120 131
   $id = (int) $id;
... ...
@@ -134,6 +145,7 @@ function make_svn_vhost($id)
134 145
     system_failure("id == 0");
135 146
   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Converting vhost #'.$id.' to SVN');
136 147
   db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES ({$id}, 'svn')");
148
+  db_query("DELETE FROM vhosts.webapps WHERE vhost={$id}");
137 149
 }
138 150
 
139 151
 function make_dav_vhost($id) 
... ...
@@ -143,30 +155,34 @@ function make_dav_vhost($id)
143 155
     system_failure("id == 0");
144 156
   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
145 157
   db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES ({$id}, 'dav')");
158
+  db_query("DELETE FROM vhosts.webapps WHERE vhost={$id}");
146 159
 }
147 160
 
148
-function no_dav_or_svn($id)
161
+function make_regular_vhost($id)
149 162
 {
150 163
   $id = (int) $id;
151 164
   if ($id == 0)
152 165
     system_failure("id == 0");
153 166
   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Converting vhost #'.$id.' to regular');
154 167
   db_query("DELETE FROM vhosts.dav WHERE vhost={$id}");
168
+  db_query("DELETE FROM vhosts.webapps WHERE vhost={$id}");
155 169
 }
156 170
 
157 171
 
158
-/*
159 172
 function make_webapp_vhost($id, $webapp) 
160 173
 {
161 174
   $id = (int) $id;
162 175
   $webapp = (int) $webapp;
163 176
   if ($id == 0)
164 177
     system_failure("id == 0");
165
-  logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Setting up webapp # '.$webapp.' on vhost #'.$id);
166
-  db_query("INSERT INTO vhosts.webapps (vhost, webapp) VALUES ({$id}, {$webapp})");
167
-
178
+  $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id={$webapp};");
179
+  if (mysql_num_rows($result) == 0)
180
+    system_failure("webapp-id invalid");
181
+  $webapp_name = mysql_fetch_object($result)->displayname;
182
+  logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Setting up webapp '.$webapp_name.' on vhost #'.$id);
183
+  db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES ({$id}, {$webapp})");
184
+  mail('webapps-setup@schokokeks.org', 'setup', 'setup');
168 185
 }
169
-*/
170 186
 
171 187
 
172 188
 function save_vhost($vhost)
... ...
@@ -196,12 +212,19 @@ function save_vhost($vhost)
196 212
     $result = db_query("INSERT INTO vhosts.vhost (user, hostname, domain, docroot, php, `ssl`, logtype, errorlog, options) VALUES ({$_SESSION['userinfo']['uid']}, {$hostname}, {$domain}, {$docroot}, {$php}, {$ssl}, {$logtype}, {$errorlog}, '{$options}')");
197 213
     $id = mysql_insert_id();
198 214
   }
199
-  if ($vhost['is_dav'] == 1)
215
+  $oldvhost = get_vhost_details($id);
216
+  /*
217
+    these vars may be 0 or 1.
218
+    So newval > oldval means that it has been switched on yet.
219
+  */
220
+  if ($vhost['is_dav'] > $oldvhost['is_dav'])
200 221
       make_dav_vhost($id);
201
-  elseif ($vhost['is_svn'] == 1)
222
+  elseif ($vhost['is_svn'] > $oldvhost['is_svn'])
202 223
       make_svn_vhost($id);
203
-  else
204
-      no_dav_or_svn($id);
224
+  elseif ($vhost['is_webapp'] > $oldvhost['is_webapp'])
225
+      make_webapp_vhost($id, $vhost['webapp_id']);
226
+  elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0)
227
+      make_regular_vhost($id);
205 228
 }
206 229
 
207 230
 
... ...
@@ -79,6 +79,7 @@ if ($_GET['action'] == 'edit')
79 79
     $vhost['is_dav'] = 0;
80 80
     $vhost['is_svn'] = 0;
81 81
     $vhost['is_webapp'] = 1;
82
+    $vhost['webapp_id'] = (int) $_POST['webapp'];
82 83
   }
83 84
 
84 85