Re: cvs: pearweb /public_html authors.php test.php /sql Makefile addusers.php cvs_acl.sql data.php users.sql
| From: | Andrei Zmievski | Date: | Mon, 12 Nov 2001 15:35:01 +0000 |
| Subject: | Re: cvs: pearweb /public_html authors.php test.php /sql Makefile addusers.php cvs_acl.sql data.php users.sql | ||
| References: | 1 | Groups: | php.pear.cvs |
| Request: | Send a blank email to pear-cvs+get-1302@lists.php.net to get a copy of this message | ||
This is getting more and more tantalizing. When will it actually run on
pear.php.net? :)
On Mon, 12 Nov 2001, Stig Bakken wrote:
> ssb Mon Nov 12 09:04:17 2001 EDT
>
> Added files:
> /pearweb/sql cvs_acl.sql
>
> Modified files:
> /pearweb/public_html authors.php test.php
> /pearweb/sql Makefile addusers.php data.php users.sql
> Log:
> * implemented paging in author/user browser
>
>
> Index: pearweb/public_html/authors.php
> diff -u pearweb/public_html/authors.php:1.10 pearweb/public_html/authors.php:1.11
> --- pearweb/public_html/authors.php:1.10 Thu Sep 27 21:11:34 2001
> +++ pearweb/public_html/authors.php Mon Nov 12 09:04:17 2001
> @@ -1,53 +1,120 @@
> <?php
>
> -response_header("PEAR: Authors");
> +response_header("Users");
>
> -print "<H1>Authors</H1>\n";
> +$page_size = 20;
>
> -$sth = $dbh->query('SELECT handle,name,email,homepage,showemail '.
> - 'FROM users WHERE registered = 1');
> +print "<H1>Users</H1>\n";
> +
> +$all_firstletters = $dbh->getCol('SELECT SUBSTRING(handle,1,1) FROM users '.
> + 'WHERE registered = 1 ORDER BY handle');
> +// I wish there was a way to do this in mysql...
> +$first_letter_offsets = array();
> +for ($i = 0; $i < sizeof($all_firstletters); $i++) {
> + $l = $all_firstletters[$i];
> + if (isset($first_letter_offsets[$l])) {
> + continue;
> + }
> + $first_letter_offsets[$l] = $i;
> +}
> +
> +if (preg_match('/^[a-z]$/i', @$letter)) {
> + $offset = $first_letter_offsets[$letter];
> + $offset -= $offset % $page_size;
> +}
> +
> +if (empty($show)) {
> + $show = $page_size;
> +} else {
> + settype($show, "int");
> +}
> +settype($offset, "int");
> +
> +$nauthors = $dbh->getOne("SELECT COUNT(handle) FROM users ".
> + "WHERE registered = 1");
> +
> +$last_shown = $offset + $page_size - 1;
> +
> +$firstletters = array_unique($all_firstletters);
> +
> +$last = $offset - $page_size;
> +$lastlink = "$PHP_SELF?offset=$last";
> +$next = $offset + $page_size;
> +$nextlink = "$PHP_SELF?offset=$next";
> +print "<table border=\"0\" cellspacing=\"1\"
> cellpadding=\"5\">\n";
> +print " <tr bgcolor=\"#cccccc\">\n";
> +print " <th>";
> +if ($offset > 0) {
> + print "<a href=\"$lastlink\"><< Last
> $page_size</a>";
> +} else {
> + print " ";
> +}
> +print "</th>\n";
> +print " <td colspan=\"3\">";
> +
> +foreach ($firstletters as $fl) {
> + $o = $first_letter_offsets[$fl];
> + if ($o >= $offset && $o <= $last_shown) {
> + printf('<b>%s</b> ', strtoupper($fl));
> + } else {
> + printf('<a href="%s?letter=%s">%s</a> ',
> + $PHP_SELF, $fl, strtoupper($fl));
> + }
> +}
> +printf("<br />Displaying users %d - %d of %d<br />\n",
> + $offset, min($offset+$show, $nauthors), $nauthors);
> +$sth = $dbh->limitQuery('SELECT handle,name,email,homepage,showemail '.
> + 'FROM users WHERE registered = 1 ORDER BY handle',
> + $offset, $show);
> if (DB::isError($sth)) {
> die("query failed: ".DB::errorMessage($dbh)."<BR>\n");
> }
> +print "</td>\n";
> +print " <th>";
> +if ($offset + $page_size < $nauthors) {
> + $nn = min($page_size, $nauthors - $offset - $page_size);
> + print "<a href=\"$nextlink\">Next $nn >></a>";
> +} else {
> + print " ";
> +}
> +print "</th>\n";
> +print " </tr>\n";
>
> -print "<P>\n";
> -
> -print "<TABLE BORDER=\"0\" CELLSPACING=\"1\"
> CELLPADDING=\"5\">\n";
> -print " <TR bgcolor=\"#CCCCCC\">\n";
> -print " <TH>Handle</TH>\n";
> -print " <TH>Name</TH>\n";
> -print " <TH>Email</TH>\n";
> -print " <TH>Homepage</TH>\n";
> -print " <TH>Commands</TH>\n";
> -print " </TR>\n";
> +print " <tr bgcolor=\"#CCCCCC\">\n";
> +print " <th>Handle</th>\n";
> +print " <th>Name</th>\n";
> +print " <th>Email</th>\n";
> +print " <th>Homepage</th>\n";
> +print " <th>Commands</th>\n";
> +print " </tr>\n";
>
> $rowno = 0;
> while (is_array($row = $sth->fetchRow(DB_FETCHMODE_ASSOC))) {
> extract($row);
> if (++$rowno % 2) {
> - print " <TR bgcolor=\"#e8e8e8\">\n";
> + print " <tr bgcolor=\"#e8e8e8\">\n";
> } else {
> - print " <TR BGCOLOR=\"#e0e0e0\">\n";
> + print " <tr bgcolor=\"#e0e0e0\">\n";
> }
> - print " <TD>$handle</TD>\n";
> - print " <TD>$name</TD>\n";
> + print " <td>$handle</td>\n";
> + print " <td>$name</td>\n";
>
> if ($showemail) {
> - print " <TD><A
> HREF=\"mailto:$email\">$email</A></TD>\n";
> + print " <td><a href=\"mailto:$email\"ÖC'Hc
> ® ©¨€ƒQ>$email</a></td>\n";
> } else {
> - print " <TD>(not shown)</TD>\n";
> + print " <td>(not shown)</td>\n";
> }
> if (!empty($homepage)) {
> - print "<TD><A
> HREF=\"$homepage\">$homepage</A></TD>";
> + print "<td><a
> href=\"$homepage\">$homepage</a></td>";
> } else {
> - print '<TD> </TD>';
> + print '<td> </td>';
> }
> - print "\n <TD><A
> HREF=\"edit-author.php?handle=".$row['handle']."\">[edit]</A>
> - <A
> HREF=\"detail-author.php?handle=".$row['handle']."\">[details]</A></TD>\n";
> - print " </TR>\n";
> + print "\n <td><a
> href=\"edit-author.php?handle=".$row['handle']."\">[E]</a>
> + <a
> href=\"detail-author.php?handle=".$row['handle']."\">[I]</A></td>\n";
> + print " </tr>\n";
> }
>
> -print "</TABLE>\n";
> +print "</table>\n";
>
> response_footer();
>
> Index: pearweb/public_html/test.php
> diff -u pearweb/public_html/test.php:1.6 pearweb/public_html/test.php:1.7
> --- pearweb/public_html/test.php:1.6 Wed Nov 7 05:42:39 2001
> +++ pearweb/public_html/test.php Mon Nov 12 09:04:17 2001
> @@ -1,46 +1,6 @@
> <?php
>
> -require_once "signatures.php";
> -
> -parse_signatures_from_file("../include/pear-database.php", &$signatures,
> - "index");
> -
> -pre_dump($signatures);
> -
> -exit;
> -print "<pre>";
> -$ret = "<introspection version='1.0'>\n";
> -$ret .= " <methodList>\n";
> -foreach ($signatures as $sig) {
> - $ret .= " <methodDescription name='$sig[method_name]'>\n";
> - $ret .= " <author/>\n";
> - $ret .= " <purpose/>\n";
> - $ret .= " <signatures>\n";
> - foreach ($sig["param_types"] as $params) {
> - $ret .= " <signature>\n";
> - $ret .= " <params>\n";
> - $paramlist = explode(",", $params);
> - foreach ($paramlist as $param) {
> - $ret .= " <value type='$param'/>\n";
> - }
> - $ret .= " </params>\n";
> - $ret .= " <returns>\n";
> - $ret .= " <value type='$sig[return_type]'/>\n";
> - $ret .= " </returns>\n";
> - $ret .= " </signature>\n";
> - }
> - $ret .= " </signatures>\n";
> - $ret .= " <see/>\n";
> - $ret .= " <examples/>\n";
> - $ret .= " <errors/>\n";
> - $ret .= " <notes/>\n";
> - $ret .= " <bugs/>\n";
> - $ret .= " <todo/>\n";
> - $ret .= " </methodDescription>\n";
> -}
> -$ret .= " </methodList>\n";
> -$ret .= "</introspection>\n";
> -print htmlspecialchars($ret);
> -print "</pre>\n";
> +$arr = array(1,1,2,2,3,3);
> +var_dump(array_search(2,$arr));
>
> ?>
> Index: pearweb/sql/Makefile
> diff -u pearweb/sql/Makefile:1.13 pearweb/sql/Makefile:1.14
> --- pearweb/sql/Makefile:1.13 Thu Sep 27 20:53:32 2001
> +++ pearweb/sql/Makefile Mon Nov 12 09:04:17 2001
> @@ -18,6 +18,7 @@
> #
>
> TABLE_FILES=\
> + cvs_acl.sql \
> package_acl.sql \
> maintains.sql \
> categories.sql \
> @@ -107,3 +108,4 @@
> users.res:
> notes.res: packages.res users.res
> categories.res:
> +cvs_acl.res: users.res
> Index: pearweb/sql/addusers.php
> diff -u pearweb/sql/addusers.php:1.3 pearweb/sql/addusers.php:1.4
> --- pearweb/sql/addusers.php:1.3 Sat Nov 3 02:05:19 2001
> +++ pearweb/sql/addusers.php Mon Nov 12 09:04:17 2001
> @@ -2,7 +2,7 @@
>
> print "Adding users...\n";
>
> -$users = '
> +$hardcoded_users = '
> alexmerz;*;Alexander Merz;;0
> chregu;*;Christian Stocker;;0
> cox;124854bf5ca680411fca8676e6014819;Tomas V.V.Cox;;1
> @@ -12,28 +12,76 @@
> mj;4f5c2e35084da4469fb82cc494eeb847;Martin Jansen;;1
> sebastian;*;Sebastian Bergmann;;0
> sn;*;Sebastian Nohn;sebastian@nohn.net;0
> -ssb;aaXRbnur6Ub86;Stig S. Bakken;;1
> +ssb;aaXRbnur6Ub86;Stig S. Bakken;ssb@fast.no;1
> zyprexia;*;Dave Mertens;dmertens@zyprexia.com;0
> jimw;aai6p0orwS6qE;Jim Winstead;jimw@apache.org;1
> andi;5rPeqa6EffAsk;Andi Gutmans;andi@zend.com;1
> +rasmus;;;;1
> +zeev;;;;1
> +jimw;;;;1
> +thies;;;;1
> ';
>
> +$users = array(); // array(user=>array(user,pw,name,email,admin),...)
> +foreach (explode("\n", $hardcoded_users) as $line) {
> + $line = trim($line);
> + if (empty($line)) {
> + continue;
> + }
> + $tmp = explode(";", trim($line));
> + $users[$tmp[0]]['user'] = $tmp[0];
> + $users[$tmp[0]]['pw'] = $tmp[1];
> + $users[$tmp[0]]['name'] = $tmp[2];
> + $users[$tmp[0]]['email'] = $tmp[3];
> + $users[$tmp[0]]['admin'] = $tmp[4];
> +}
> +
> +if (is_resource($fp = @fopen("cvsusers", "r"))) {
> + while ($line = fgets($fp, 1024)) {
> + if (!trim($line)) continue;
> + list($user,$name,$email) = explode(":", trim($line));
> + $name = preg_replace('/\s\s+/', ' ', $name);
> + $users[$user]['user'] = $user;
> + $users[$user]['name'] = $name;
> + $users[$user]['email'] = $email;
> + }
> + fclose($fp);
> +}
> +
> +if (is_resource($fp = @fopen("passwd", "r"))) {
> + while ($line = fgets($fp, 1024)) {
> + if (!trim($line)) continue;
> + list($user,$pw,$groups) = explode(":", trim($line));
> + $users[$user]['pw'] = $pw;
> + }
> + fclose($fp);
> +}
> +
> +//print_r($users);exit;
> +
> $sth = $dbh->prepare("INSERT INTO users ".
> "(handle,password,name,email,registered,showemail," .
> "created,createdby,admin)".
> " VALUES(?,?,?,?,1,1,?,?,?)");
> $me = getenv("USER");
> $now = gmdate("Y-m-d H:i:s");
> -foreach (explode("\n", $users) as $line) {
> - if (trim($line) == '') {
> - continue;
> - }
> - list($user,$pw,$name,$email,$admin) = explode(";", trim($line));
> +$users_added = 0;
> +foreach ($users as $username => $info) {
> + $user = $username;
> + $pw = $info['pw'];
> + $name = $info['name'];
> + if (empty($info['email'])) {
> + $email = "$user@php.net";
> + } else {
> + $email = $info['email'];
> + }
> + $admin = (bool)$info['admin'];
> if (empty($email)) {
> - $email = "{$user}@php.net";
> + $email = "{$user}@php.net";
> }
> $dbh->execute($sth, array($user,$pw,$name,$email,$now,$me,$admin));
> - print "User: $user\n";
> + $users_added++;
> }
> +print "$users_added users added.\n";
>
> ?>
> Index: pearweb/sql/data.php
> diff -u pearweb/sql/data.php:1.5 pearweb/sql/data.php:1.6
> --- pearweb/sql/data.php:1.5 Tue Sep 4 01:10:31 2001
> +++ pearweb/sql/data.php Mon Nov 12 09:04:17 2001
> @@ -3,12 +3,21 @@
> require_once "DB.php";
> require_once "../include/pear-database.php";
>
> -PEAR::setErrorHandling(PEAR_ERROR_DIE);
> +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "error_handler");
> list($progname, $type, $user, $pass, $db) = $argv;
> $dbh = DB::connect("$type://$user:$pass@localhost/$db");
>
> include "./addusers.php";
> include "./addcategories.php";
> include "./addpackages.php";
> +
> +function error_handler($obj) {
> + print "Error when adding users: ";
> + print $obj->getMessage();
> + print "\nMore info: ";
> + print $obj->getUserInfo();
> + print "\n";
> + exit;
> +}
>
> ?>
> Index: pearweb/sql/users.sql
> diff -u pearweb/sql/users.sql:1.2 pearweb/sql/users.sql:1.3
> --- pearweb/sql/users.sql:1.2 Wed Apr 18 04:44:29 2001
> +++ pearweb/sql/users.sql Mon Nov 12 09:04:17 2001
> @@ -13,4 +13,5 @@
> userinfo TEXT,
>
> PRIMARY KEY(handle)
> + INDEX(handle,registered)
> );
>
> Index: pearweb/sql/cvs_acl.sql
> +++ pearweb/sql/cvs_acl.sql
> CREATE TABLE cvs_acl (
> handle VARCHAR(20) NOT NULL REFERENCES users(handle),
> path VARCHAR(250) NOT NULL,
> access BOOL,
>
> UNIQUE INDEX(handle,path)
> );
>
> --
> PEAR CVS Mailing List (http://pear.php.net/)
> To unsubscribe, e-mail: pear-cvs-unsubscribe@lists.php.net
> For additional commands, e-mail: pear-cvs-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
-Andrei
* I don't have a solution but I admire the problem. *