cvs: pearweb /public_html package-new.php

[email protected] ("Helgi ?ormar ?orbj?rnsson") Thu, 08 May 2008 20:48:22 -0000
Newsgroups php.pear.cvs,php.pear.core
Message-ID <cvsdufuz1210279702@cvsserver>
dufuz		Thu May  8 20:48:22 2008 UTC

  Modified files:              
    /pearweb/public_html	package-new.php 
  Log:
  Improve the recusion for the category select box and make it more readable
  
http://cvs.php.net/viewvc.cgi/pearweb/public_html/package-new.php?r1=1.44&r2=1.45&diff_format=u
Index: pearweb/public_html/package-new.php
diff -u pearweb/public_html/package-new.php:1.44 pearweb/public_html/package-new.php:1.45
--- pearweb/public_html/package-new.php:1.44	Sat Mar  8 21:49:47 2008
+++ pearweb/public_html/package-new.php	Thu May  8 20:48:22 2008
@@ -15,7 +15,7 @@
    +----------------------------------------------------------------------+
    | Authors:                                                             |
    +----------------------------------------------------------------------+
-   $Id: package-new.php,v 1.44 2008/03/08 21:49:47 dufuz Exp $
+   $Id: package-new.php,v 1.45 2008/05/08 20:48:22 dufuz Exp $
 */
 
 require_once 'HTML/QuickForm.php';
@@ -27,9 +27,8 @@
 auth_require('pear.dev');
 
 $display_form = true;
-$width = 60;
-$errors = array();
-$jumpto = 'name';
+$errors       = array();
+$jumpto       = 'name';
 
 $valid_args = array('submit', 'name','category','license','summary','desc','homepage','cvs_link');
 foreach ($valid_args as $arg) {
@@ -90,17 +89,13 @@
 } while (false);
 
 if ($display_form) {
-    $title = "New Package";
-    response_header($title);
-
-    echo "<h1>$title</h1>\n";
-
+    response_header('New Package');
+    echo "<h1>New Package</h1>\n";
     report_error($errors);
-
-    ?>
+?>
 
 <p>
-  Use this form to register a new package.
+ Use this form to register a new package.
 </p>
 
 <p>
@@ -116,41 +111,35 @@
  So please play nice, that way we can keep the bureaucracy at a minimum.
 </p>
 
-    <?php
-
+<?php
     // get parent categories
-    $parentcategories = $dbh->getAssoc("SELECT id,name FROM categories
-        WHERE parent IS NULL ORDER BY name");
+    $sql = 'SELECT id, name FROM categories WHERE parent IS NULL ORDER BY name';
+    $parents = $dbh->getAssoc($sql);
     // get child categories
-    $children = $dbh->getAll("SELECT parent,id,name FROM categories
-        WHERE parent IS NOT NULL ORDER BY parent, name");
-    $childcategories = array();
-    foreach ($children as $cinfo) {
-        $id = array_shift($cinfo);
-        $childcategories[$id][] = $cinfo;
+    $sql = 'SELECT id, parent, name FROM categories WHERE parent IS NOT NULL ORDER BY parent, name';
+    $kids = $dbh->getAssoc($sql);
+    $children = array();
+    foreach ($kids as $id => $c) {
+        $children[$c[0]][$id] = $c[1];
     }
 
     $categories = array();
     $categories[''] = '-- Select Category --';
-    function recur_categories($childcategories, $parentcategories, $me,
-                              &$categories, $indent = '--')
+
+    function recur_categories($children, $parents, $me, &$categories, $indent = '--')
     {
-        foreach ($childcategories[$me] as $category) {
-            $nid = $category[0];
-            $category = $category[1];
-            $category = $indent . $category;
-            $categories[$nid] = $category;
-            if (isset($childcategories[$nid])) {
-                recur_categories($childcategories, $parentcategories, $nid, $categories,
-                    $indent . '--');
+        foreach ($children[$me] as $nid => $category) {
+            $categories[$nid] = $indent . ' ' . $category;
+            if (isset($children[$nid])) {
+                recur_categories($children, $parents, $nid, $categories, $indent . '--');
             }
         }
     }
-    foreach ($parentcategories as $id => $category) {
+
+    foreach ($parents as $id => $category) {
         $categories[$id] = $category;
-        if (isset($childcategories[$id])) {
-            recur_categories($childcategories, $parentcategories, $id, $categories,
-                '--');
+        if (isset($children[$id])) {
+            recur_categories($children, $parents, $id, $categories, '--');
         }
     }
 
@@ -195,8 +184,8 @@
     $form->addElement('text', 'name', 'Package Name', array('size' => 20));
     $form->addElement('text', 'license', 'License', array('size' => 20));
     $form->addElement('select', 'category', 'Category', $categories);
-    $form->addElement('textarea', 'summary', 'Summary', array('cols' => $width));
-    $form->addElement('textarea', 'desc', 'Full description', array('cols' => $width, 'rows' => 3));
+    $form->addElement('textarea', 'summary', 'Summary', array('cols' => 60));
+    $form->addElement('textarea', 'desc', 'Full description', array('cols' => 60, 'rows' => 3));
     $form->addElement('text', 'homepage', 'Additional project homepage', array('size' => 40));
     $form->addElement('text', 'cvs_link', 'CVS Web URL', array('size' => 40));
     $form->addElement('static', null, null, '<small>For example: http://cvs.php.net/cvs.php/pear/XML_Parser</small>');
@@ -208,8 +197,6 @@
         echo "document.forms[1].$jumpto.focus();\n";
         echo "// -->\n</script>\n";
     }
-
-    echo "</form>\n";
 }
 
 response_footer();
\ No newline at end of file