cvs: pearweb /include pear-database-category.php /public_html/admin category-manager.php /templates category-manager.html

From: Date: Sun, 17 May 2009 04:44:33 +0000
Subject: cvs: pearweb /include pear-database-category.php /public_html/admin category-manager.php /templates category-manager.html
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-8415@lists.php.net to get a copy of this message
clockwerx Sun May 17 04:44:33 2009 UTC Modified files: /pearweb/templates category-manager.html /pearweb/public_html/admin category-manager.php /pearweb/include pear-database-category.php Log: Usability / Layout overhaul of category manager tool; and the use of arguments to prevent sql injection / unexpected errors

http://cvs.php.net/viewvc.cgi/pearweb/templates/category-manager.html?r1=1.5&r2=1.6&diff_format=u Index: pearweb/templates/category-manager.html diff -u pearweb/templates/category-manager.html:1.5 pearweb/templates/category-manager.html:1.6 --- pearweb/templates/category-manager.html:1.5 Fri Dec 10 18:10:13 2004 +++ pearweb/templates/category-manager.html Sun May 17 04:44:32 2009 @@ -1,166 +1,156 @@ <?php response_header(); ?> -<script language="JavaScript" type="text/javascript" src="/javascript/TreeMenu/TreeMenu.js"></script> -<script language="JavaScript" type="text/javascript"> +<script type="text/javascript" src="/javascript/TreeMenu/TreeMenu.js"></script> +<script type="text/javascript"> <!-- - currentHighlight = null; + currentHighlight = null; - function category_click(e, obj, catID) - { - if (e === null && currentHighlight !== null) { - document.getElementById(currentHighlight).className = 'treeMenuOff'; - currentHighlight = null; - updateForm(null); - return; - } else if (e === null) { - return; - } - - if (e) { - e.cancelBubble = true; - } - - var layerID = obj.parentNode.parentNode.id; - - if (currentHighlight != layerID) { - if (currentHighlight !== null) { - document.getElementById(currentHighlight).className = 'treeMenuOff'; - } - var layerRef = document.getElementById(layerID); - layerRef.className = (layerRef.className == 'treeMenuOff' ? 'treeMenuOn' : 'treeMenuOff'); - updateForm(catID); - currentHighlight = layerID; - } - } - - /** - * Updates form with correct cateogry parent name/id - */ - function updateForm(catID) - { - var formObj = document.forms['category_form']; - if (catID !== null) { - formObj.parent_text.value = categories[catID][0]; - formObj.cat_parent.value = catID; - formObj.delete_text.value = categories[catID][0]; - formObj.cat_delete.value = catID; - } else { - formObj.parent_text.value = 'none'; - formObj.cat_parent.value = ''; - formObj.delete_text.value = 'none'; - formObj.cat_delete.value = ''; - } - } - - /** - * Called when update checkbox is clicked - */ - function updateCheckToggle(obj) - { - var newStatus = obj.checked; - var formObj = document.forms['category_form']; - - if (newStatus && formObj.parent_text.value != 'none') { - formObj.catName.value = categories[formObj.cat_parent.value][0]; - formObj.catDesc.value = categories[formObj.cat_parent.value][1] == 'none' ? '' : categories[formObj.cat_parent.value][1]; - formObj.addUpdateSubmit.value = 'Update category'; - formObj.action.value = 'update'; - } else { - formObj.catName.value = ''; - formObj.catDesc.value = ''; - formObj.addUpdateSubmit.value = 'Add category'; - formObj.action.value = 'add'; - } - } - - categories = new Array(); + function category_click(e, obj, catID) + { + if (e === null && currentHighlight !== null) { + document.getElementById(currentHighlight).className = 'treeMenuOff'; + currentHighlight = null; + updateForm(null); + return; + } else if (e === null) { + return; + } + + if (e) { + e.cancelBubble = true; + } + + var layerID = obj.parentNode.parentNode.id; + + if (currentHighlight != layerID) { + if (currentHighlight !== null) { + document.getElementById(currentHighlight).className = 'treeMenuOff'; + } + var layerRef = document.getElementById(layerID); + layerRef.className = (layerRef.className == 'treeMenuOff' ? 'treeMenuOn' : 'treeMenuOff'); + updateForm(catID); + currentHighlight = layerID; + } + } + + /** + * Updates form with correct cateogry parent name/id + */ + function updateForm(catID) + { + var formObj = document.forms['category_form']; + if (catID !== null) { + formObj.parent_text.value = categories[catID][0]; + formObj.cat_parent.value = catID; + formObj.delete_text.value = categories[catID][0]; + formObj.cat_delete.value = catID; + } else { + formObj.parent_text.value = 'none'; + formObj.cat_parent.value = ''; + formObj.delete_text.value = 'none'; + formObj.cat_delete.value = ''; + } + } + + /** + * Called when update checkbox is clicked + */ + function updateCheckToggle(obj) + { + var newStatus = obj.checked; + var formObj = document.forms['category_form']; + + if (newStatus && formObj.parent_text.value != 'none') { + formObj.catName.value = categories[formObj.cat_parent.value][0]; + formObj.catDesc.value = categories[formObj.cat_parent.value][1] == 'none' ? '' : categories[formObj.cat_parent.value][1]; + formObj.addUpdateSubmit.value = 'Update category'; + formObj.action.value = 'update'; + } else { + formObj.catName.value = ''; + formObj.catDesc.value = ''; + formObj.addUpdateSubmit.value = 'Add category'; + formObj.action.value = 'add'; + } + } + + categories = new Array(); - <?php foreach($categories as $c):?> + <?php foreach($categories as $c):?> categories[<?php echo $c['id']; ?>] = new Array('<?php echo $c['name']; ?>', '<?php echo $c['description']; ?>'); - <?php endforeach ?> + <?php endforeach ?> //--> </script> <style type="text/css"> <!-- - .treeMenuContainer { - height: 400px; - width: 220px; - overflow: auto; - border: 1px #aaaaaa solid; - background-color: #eeeeee; - } - - .treeMenuOff { - padding: 1px; - width: 202x; - cursor: pointer; - cursor: hand; - } - - .treeMenuOn { - border: 1px solid #000080; - background-color: #adadd1; - width: 202px; - cursor: pointer; - cursor: hand; - } + .treeMenuContainer { + height: 400px; + width: 220px; + overflow: auto; + border: 1px #aaaaaa solid; + background-color: #eeeeee; + float: left; + padding: 0.5em; + margin-right: 1.0em; + } + + .treeMenuContainer h4 { + margin-bottom: 0.5em; + } + + .treeMenuOff { + padding: 1px; + width: 202x; + cursor: pointer; + cursor: hand; + } + + .treeMenuOn { + border: 1px solid #000080; + background-color: #adadd1; + width: 202px; + cursor: pointer; + cursor: hand; + } + + textarea { + margin: 0; + } // --> </style> -<table> - <tr> - <td> - <div class="treeMenuContainer" onclick="category_click(null)"> - <?php $treeMenuPres->printMenu(); ?> - </div> - </td> - <td valign="top"> - <div class="errors"><?php echo @$message; ?></div> - - <form action="category-manager.php" name="category_form" method="post"> - <input type="hidden" name="action" value="" /> - <input type="hidden" name="cat_parent" value="" /> - <input type="hidden" name="cat_delete" value="" /> - - <h2>&raquo; Add New Category</h2> - <table> - <tr> - <td>Parent:</td> - <td><input type="text" value="none" size="25" disabled="disabled" name="parent_text" /></td> - </tr> - <tr> - <td>Name</td> - <td><input type="text" name="catName" size="25" /></td> - </tr> - <tr> - <td>Description</td> - <td><input type="text" name="catDesc" size="25" /></td> - </tr> - <tr> - <td>&nbsp;</td> - <td><input type="checkbox" name="update_checkbox" onclick="updateCheckToggle(this)" id="update_checkbox" /> <label for="update_checkbox">Update instead of addition?</label></td> - </tr> - <tr> - <td>&nbsp;</td> - <td><input type="submit" value="Add category" name="addUpdateSubmit" onclick="document.forms['category_form'].action.value = (this.value == 'Add category' ? 'add' : 'update')" /></td> - </tr> - </table> - - <h2>&raquo; Delete category</h2> - <table> - <tr> - <td>Selected:</td> - <td><input type="text" name="delete_text" value="none" size="25" disabled="disabled" /></td> - </tr> - <tr> - <td>&nbsp;</td> - <td><input type="submit" value="Delete category" onclick="document.forms['category_form'].action.value = 'delete'; return confirm('Are you sure you wish to delete this category?')" /></td> - </tr> - </table> - </form> - </td> - </tr> -</table> + <?php if (!empty($message)) { ?> + <div class="errors"><?php echo $message; ?></div> + <?php } ?> + + <div class="treeMenuContainer" onclick="category_click(null)"> + <h4>Categories</h4> + <?php $treeMenuPres->printMenu(); ?> + </div> + + + <form action="category-manager.php" name="category_form" method="post"> + <input type="hidden" name="action" value="" /> + <input type="hidden" name="cat_parent" value="" /> + <input type="hidden" name="cat_delete" value="" /> + + <h2>&raquo; Add New Category</h2> + <p>Parent Category<br /><input type="text" value="none" size="25" disabled="disabled" name="parent_text" /></p> + <p>Name<br /><input type="text" name="catName" size="25" /></p> + <p>Description<br /><textarea name="catDesc"></textarea></p> + + + <p><input type="checkbox" name="update_checkbox" onclick="updateCheckToggle(this)" id="update_checkbox" /> <label for="update_checkbox">Update instead of addition?</label></p> + + <p><input type="submit" value="Add category" name="addUpdateSubmit" onclick="document.forms['category_form'].action.value = (this.value == 'Add category' ? 'add' : 'update')" /></p> + + + + <h2>&raquo; Delete category</h2> + <p>Selected <br /> + <input type="text" name="delete_text" value="none" size="25" disabled="disabled" /></p> + + <p><input type="submit" value="Delete category" onclick="document.forms['category_form'].action.value = 'delete'; return confirm('Are you sure you wish to delete this category?')" /></p> + </form> <?php response_footer(); ?> http://cvs.php.net/viewvc.cgi/pearweb/public_html/admin/category-manager.php?r1=1.7&r2=1.8&diff_format=u Index: pearweb/public_html/admin/category-manager.php diff -u pearweb/public_html/admin/category-manager.php:1.7 pearweb/public_html/admin/category-manager.php:1.8 --- pearweb/public_html/admin/category-manager.php:1.7 Fri Feb 29 20:35:59 2008 +++ pearweb/public_html/admin/category-manager.php Sun May 17 04:44:33 2009 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Authors: Richard Heyes | +----------------------------------------------------------------------+ - $Id: category-manager.php,v 1.7 2008/02/29 20:35:59 dufuz Exp $ + $Id: category-manager.php,v 1.8 2009/05/17 04:44:33 clockwerx Exp $ */ auth_require(true); @@ -107,7 +107,7 @@ /** * Create the menu, set the db to assoc mode */ -require_once('HTML/TreeMenu.php'); +require_once 'HTML/TreeMenu.php'; $treeMenu = new HTML_TreeMenu(); /** @@ -127,4 +127,12 @@ $categories = $dbh->getAll('SELECT id, name, description FROM categories ORDER BY id', null, DB_FETCHMODE_ASSOC); $treeMenuPres = new HTML_TreeMenu_DHTML($treeMenu, array('images' => '../gifs/TreeMenu', 'defaultClass' => 'treeMenuOff')); -include PEARWEB_TEMPLATEDIR . 'category-manager.html'; \ No newline at end of file +include_once 'pear-rest.php'; +global $dbh; +$pear_rest = new pearweb_Channel_REST_Generator(PEAR_REST_PATH, $dbh); + +if (!is_writable($pear_rest->getCategoryDirectory())) { + $message = 'Warning: ' . $pear_rest->getCategoryDirectory() . ' is not writable'; +} + +include PEARWEB_TEMPLATEDIR . 'category-manager.html'; http://cvs.php.net/viewvc.cgi/pearweb/include/pear-database-category.php?r1=1.10&r2=1.11&diff_format=u Index: pearweb/include/pear-database-category.php diff -u pearweb/include/pear-database-category.php:1.10 pearweb/include/pear-database-category.php:1.11 --- pearweb/include/pear-database-category.php:1.10 Fri Jan 23 11:50:44 2009 +++ pearweb/include/pear-database-category.php Sun May 17 04:44:33 2009 @@ -18,7 +18,7 @@ | Martin Jansen <mj@php.net> | | Richard Heyes <richard@php.net> | +----------------------------------------------------------------------+ - $Id: pear-database-category.php,v 1.10 2009/01/23 11:50:44 dufuz Exp $ + $Id: pear-database-category.php,v 1.11 2009/05/17 04:44:33 clockwerx Exp $ */ // These classes correspond to tables and methods define operations on @@ -126,20 +126,20 @@ $name = $GLOBALS['dbh']->getOne('SELECT name FROM categories WHERE id = ?', array($id)); // Get parent ID if any - $parentID = $GLOBALS['dbh']->getOne('SELECT parent FROM categories WHERE id = ' . $id); + $parentID = $GLOBALS['dbh']->getOne('SELECT parent FROM categories WHERE id = ?', array($id)); // Delete it - $deleted_cat_left = $GLOBALS['dbh']->getOne('SELECT cat_left FROM categories WHERE id = ' . $id); - $deleted_cat_right = $GLOBALS['dbh']->getOne('SELECT cat_right FROM categories WHERE id = ' . $id); + $deleted_cat_left = $GLOBALS['dbh']->getOne('SELECT cat_left FROM categories WHERE id = ?', array($id)); + $deleted_cat_right = $GLOBALS['dbh']->getOne('SELECT cat_right FROM categories WHERE id = ?', array($id)); $GLOBALS['dbh']->query('DELETE FROM categories WHERE id = ' . $id); // Renumber - $GLOBALS['dbh']->query('UPDATE categories SET cat_left = cat_left - 1, cat_right = cat_right - 1 WHERE cat_left > ' . $deleted_cat_left . ' AND cat_right < ' . $deleted_cat_right); - $GLOBALS['dbh']->query('UPDATE categories SET cat_left = cat_left - 2, cat_right = cat_right - 2 WHERE cat_right > ' . $deleted_cat_right); + $GLOBALS['dbh']->query('UPDATE categories SET cat_left = cat_left - 1, cat_right = cat_right - 1 WHERE cat_left > ? AND cat_right < ?', array($deleted_cat_left, $deleted_cat_right)); + $GLOBALS['dbh']->query('UPDATE categories SET cat_left = cat_left - 2, cat_right = cat_right - 2 WHERE cat_right > ?', array($deleted_cat_right)); // Update any child categories - $GLOBALS['dbh']->query(sprintf('UPDATE categories SET parent = %s WHERE parent = %d', ($parentID ? $parentID : 'NULL'), $id)); + $GLOBALS['dbh']->query('UPDATE categories SET parent = ? WHERE parent = ?', array(($parentID ? $parentID : 'NULL'), $id)); include_once 'pear-rest.php'; $pear_rest = new pearweb_Channel_REST_Generator(PEAR_REST_PATH, $GLOBALS['dbh']); @@ -267,13 +267,13 @@ WHERE parent IS NULL"); $left = ($left !== null) ? $left : 1; // first node } else { - $left = $dbh->getOne("SELECT cat_right FROM categories WHERE id = $parent"); + $left = $dbh->getOne("SELECT cat_right FROM categories WHERE id = ?", array($parent)); } $right = $left + 1; // update my self $err = $dbh->query("UPDATE categories - SET cat_left = $left, cat_right = $right - WHERE id = $id"); + SET cat_left = ?, cat_right = ? + WHERE id = ?", array($left, $right, $id)); if (PEAR::isError($err)) { return $err; } @@ -281,13 +281,13 @@ return true; } $err = $dbh->query("UPDATE categories SET cat_left = cat_left+2 - WHERE cat_left > $left"); + WHERE cat_left > ?", array($left)); if (PEAR::isError($err)) { return $err; } // (cat_right >= $left) == update the parent but not the node itself $err = $dbh->query("UPDATE categories SET cat_right = cat_right+2 - WHERE cat_right >= $left and id <> $id"); + WHERE cat_right >= ? and id <> ?", array($left, $id)); if (PEAR::isError($err)) { return $err; }
« previous php.pear.core (#8415) next »