# # # add_file "www/common-resource.php" # content [b3df71de591444a05083859d8b5113fd75f50f8c] # # patch "schema.sql" # from [1ffd2ee143269f78ae061d03e8b36e4da1a3cc26] # to [88d60e294727d99f361429ec3f63fddece7fb67b] # # patch "www/admin-resources_backend.php" # from [40f88c5129333920a6e8ac69824d8c483c1313c3] # to [d1f490cc113924a005b87acd0228eb369e29cea6] # # patch "www/sidebar.php" # from [cc56da1425a52d7dcf3d95f5e338e58e2affaea8] # to [2cef1e1ba9df4797a7609bd19f02dc61a0517167] # ============================================================ --- www/common-resource.php b3df71de591444a05083859d8b5113fd75f50f8c +++ www/common-resource.php b3df71de591444a05083859d8b5113fd75f50f8c @@ -0,0 +1,42 @@ + +include_once("common.php"); +function resourcelist() { + global $db, $safeproj; + $query = "SELECT name, type, data FROM resources WHERE project = '%s'"; + $result = pg_exec($db, sprintf($query, $safeproj)); + $out = array(); + if ($result) { + $rows = pg_numrows($result); + for($i = 0; $i < $rows; ++$i) { + $row = pg_fetch_row ($result,$i); + $r['name'] = $row[0]; + if ($row[1] == 0) { + $r['type'] = "link"; + } elseif ($row[1] == 1) { + $r['type'] = "irc"; + } else { + $r['type'] = "unknown"; + } + $r['data'] = $row[2]; + $out[] = $r; + } + } + return $out; +} + +function get_linkstr($res) { + global $json; + $linkpat = "$s"; + if ($res['type'] == "link") { + return sprintf($linkpat, $res['data'], $res['name']); + } elseif ($res['type'] == "irc") { + $dat = $json->decode($res['data']); + $url = "irc://" + $dat.host + "/" + $dat.channel; + $link1 = sprintf($linkpat, $url, $res['name']); + $link2 = sprintf($linkpat, $data.logurl, logs); + print "$link1 ($link2)"; + } elseif ($res['type'] == "unknown") { + print $res['name'] + ": " + $res['data']; + } +} +?> ============================================================ --- schema.sql 1ffd2ee143269f78ae061d03e8b36e4da1a3cc26 +++ schema.sql 88d60e294727d99f361429ec3f63fddece7fb67b @@ -14,5 +14,6 @@ CREATE TABLE resources ( project varchar(80), name varchar(80), - url varchar(80) + type varchar(80), + data varchar(160) ); ============================================================ --- www/admin-resources_backend.php 40f88c5129333920a6e8ac69824d8c483c1313c3 +++ www/admin-resources_backend.php d1f490cc113924a005b87acd0228eb369e29cea6 @@ -1,23 +1,7 @@ include_once("common-ctrl.php"); +include_once("common-resource.php"); -function resourcelist() { - global $db, $safeproj; - $query = "SELECT name, url FROM resources WHERE project = '%s'"; - $result = pg_exec($db, sprintf($query, $safeproj)); - $out = array(); - if ($result) { - $rows = pg_numrows($result); - for($i = 0; $i < $rows; ++$i) { - $row = pg_fetch_row ($result,$i); - $r['name'] = $row[0]; - $r['url'] = $row[1]; - $out[] = $r; - } - } - return $out; -} - header('Content-type: text/x-json'); if ($action == "getresources") { @@ -35,13 +19,21 @@ $ok = false; break; } - $fields = "project, name, url"; + $fields = "project, name, type, data"; $query = sprintf("INSERT INTO resources (%s) VALUES (%%s)", $fields); - foreach ($args->newmaint as $i) { - $values = sprintf("'%s', '%s', '%s'", + foreach ($args->newresources as $i) { + if ($i->type == "link") { + $type = 0; + } elseif ($i->type == "irc") { + $type = 1; + } else { + $type = -1; + } + $values = sprintf("'%s', '%s', %s, '%s'", $safeproj, pg_escape_string($i->name), - pg_escape_string($i->url)); + $type, + pg_escape_string($i->data)); $result = pg_exec($db, sprintf($query, $values)); if (!$result) { $res['error'] = 'Internal server error. (2)'; ============================================================ --- www/sidebar.php cc56da1425a52d7dcf3d95f5e338e58e2affaea8 +++ www/sidebar.php 2cef1e1ba9df4797a7609bd19f02dc61a0517167 @@ -33,26 +33,18 @@