close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Admin Category Manager?

Thread begun 8/31/2012 4:38 pm by elevy388997 | Last modified 9/05/2012 11:53 am by Morgan | 5713 views | 26 replies |

elevy388997Beta Tester

Admin Category Manager?

I am trying to figure out how to setup an admin page for organizing categories:

View Current Category Structure (Main and Sub categories)
Add New Main Category
Add New Sub Category
Delete Main or sub category
Move Sub Category

I tried searching the forum but didn't find much. Do I need another table in the data base for the sub categories? I saw there were a lot of threads for dealing with main and sub categories. Once I get started I will have more specific questions and can search better, but for now I need a starting point. I also am interested about proper display of this setup. Should I have links to separate pages to do each task, or can I display this all in one php page with no problems?



I then also need help with the menu writer dynamic links for these categories. I figured out the main category, but without having sub categories, I can't play around with that yet. I did have a problem though... The dynamic links for each category went to -- /products_results.php?CategoryID=[CategoryID] which brought up all products regardless of what category they were in.

Sign in to reply to this post

Morgan

Hi!

Yes 2 tables would be the best, 1 for main categories and 1 for sub categories.
You should be able to have them in a singel php-page, both add/Edit/delete/move(edit)

As for Menu Writer, did you get the main category to show? And failed showing the sub categories?


I will try make a small sample and put it up when i get back home later today, se if that helps you out.
--------
Update!!
Here is the sample!


/Morgan

Sign in to reply to this post

elevy388997Beta Tester

Hello Morgan,

Thanks for the great sample. I am able to figure out a good bit through a source code. I created proper tables in my database (main and sub with correct foreign key), but I cannot seem to get a local working version. I have a proper connection to the database which I created via the SQL you included. I test the site and get a lot of code before the insert main cat section:

sqlWhereClause." ORDER BY ".$WA_joinedKeyField; $WA_mrtJoinRS = mysql_query($WA_Sql, $WA_connection) or die(mysql_error()); if (mysql_num_rows($WA_mrtJoinRS) > 0) { while ($row_WA_mrtJoinRS = mysql_fetch_assoc($WA_mrtJoinRS)) { $WA_formerString .= "^" . $row_WA_mrtJoinRS[$WA_joinedKeyField] . "^"; $WA_formerList[] = $row_WA_mrtJoinRS[$WA_joinedKeyField]; } } for ($n=0; $nsqlWhereClause; $MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error()); } } for ($n=0; $nWA_setValues . " WHERE " . $WhereObj->sqlWhereClause . ""; $MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error()); } } else { $insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1); $WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")"; $MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error()); } } } class WA_AB_InsertParams { var $WA_tableValues; var $WA_dbValues; var $WA_setValues; function WA_AB_InsertParams($WA_tableValues = "", $WA_dbValues = "", $WA_setValues = "") { $this->WA_tableValues = $WA_tableValues; $this->WA_dbValues = $WA_dbValues; $this->WA_setValues = $WA_setValues; } } function WA_AB_generateInsertParams($fieldNameList, $columnTypeList, $fieldValueList, $ignoreIndex) { $obj = new WA_AB_InsertParams(); for ($i=0; $i < sizeof($fieldNameList); $i++) { if ($i !== $ignoreIndex) { $formVal = $fieldValueList[$i]; $WA_typesArray = explode(",", $columnTypeList[$i]); $delim = ($WA_typesArray[0] != "none") ? $WA_typesArray[0] : ""; $altVal = ($WA_typesArray[1] != "none") ? $WA_typesArray[1] : ""; $emptyVal = ($WA_typesArray[2] != "none") ? $WA_typesArray[2] : ""; if ($formVal == "" || $formVal == "undefined") { $formVal = $emptyVal; } else { if ($altVal != "") { $formVal = $altVal; } else if ($delim == "'") { // escape quotes $formVal = "'".((!(preg_match("/(^|[^\\\\])'/", $formVal))) ? $formVal : addslashes($formVal))."'"; } else if ($delim == "") { //numeric if (is_numeric($formVal)) { $formVal = "".floatval($formVal); } else { $formVal = "0"; } } else { $formVal = $delim.WA_AB_clearOutSQLKeywords($formVal).$delim; } } $obj->WA_tableValues .= (($obj->WA_tableValues != "") ? "," : "") . "`" . WA_AB_cleanUpColumnName($fieldNameList[$i]) . "`"; $obj->WA_dbValues .= (($obj->WA_dbValues != "") ? "," : "") . $formVal; $obj->WA_setValues .= (($obj->WA_setValues != "") ? ", " : "") . "`" . WA_AB_cleanUpColumnName($fieldNameList[$i]) ."`" . " = " . $formVal; } } return $obj; } class WA_AB_WhereClause { var $sqlWhereClause; function WA_AB_WhereClause($sqlWhereClause = "") { $this->WA_AB_WhereClause = $sqlWhereClause; } } function WA_AB_generateWhereClause($fieldNameList, $columnTypeList, $fieldValueList, $comparisonList) { $obj = new WA_AB_WhereClause(); for ($i = 0; $i < sizeof($fieldNameList); $i++) { $formVal = $fieldValueList[$i]; $WA_typesArray = explode(",", $columnTypeList[$i]); $delim = ($WA_typesArray[0] != "none") ? $WA_typesArray[0] : ""; $altVal = ($WA_typesArray[1] != "none") ? $WA_typesArray[1] : ""; $emptyVal = ($WA_typesArray[2] != "none") ? $WA_typesArray[2] : ""; if ($formVal == "" || $formVal == "undefined") { $formVal = $emptyVal; } else { if ($altVal != "") { $formVal = $altVal; } else if ($delim == "'") { // escape quotes $formVal = "'".((!(preg_match("/(^|[^\\\\])'/", $formVal))) ? $formVal : addslashes($formVal)); if ($comparisonList[$i] == " LIKE ") $formVal .= "%";; $formVal .= "'"; } else if ($delim == "") { //numeric if (is_numeric($formVal)) { $formVal = "".floatval($formVal); } else { $formVal = "0"; } } else { $formVal = $delim.WA_AB_clearOutSQLKeywords($formVal).$delim; } } if (!($delim == "" && strpos($formVal,"()")>0)) { if ($formVal == "NULL") { $obj->sqlWhereClause .= (($i != 0) ? " AND " : "")."`". WA_AB_cleanUpColumnName($fieldNameList[$i])."`"." IS ".$formVal; } else { $obj->sqlWhereClause .= (($i != 0) ? " AND " : "")."`". WA_AB_cleanUpColumnName($fieldNameList[$i])."`".WA_AB_cleanUpEquality($comparisonList[$i]).$formVal; } } } return $obj; } function WA_AB_cleanUpColumnName($colName) { if (strpos($colName, ";") !== false) { $colName = substr($colName, 0, strpos($colName, ";")); } if (strpos($colName, "(") !== false) { $colName = substr($colName, 0, strpos($colName, "(")); } if (strpos($colName, "=") !== false) { $colName = substr($colName, 0, strpos($colName, "=")); } return $colName; } function WA_AB_cleanUpEquality($tEquality) { if (preg_replace('/^\\s*|\\s*$/', "", $tEquality) != "=") { return WA_AB_cleanUpColumnName($tEquality); } return $tEquality; } function WA_AB_clearOutSQLKeywords($tString) { if (strpos(strtolower($tString), "select") !== false) { return ""; } if (strpos(strtolower($tString), "drop") !== false) { return ""; } if (strpos(strtolower($tString), "alter") !== false) { return ""; } if (strpos(strtolower($tString), "create") !== false) { return ""; } if (strpos(strtolower($tString), "update") !== false) { return ""; } if (strpos(strtolower($tString), "insert") !== false) { return ""; } if (strpos(strtolower($tString), "delete") !== false) { return ""; } if (strpos(strtolower($tString), "'") !== false) { return ""; } if (strpos(strtolower($tString), "#") !== false) { return ""; } return $tString; } ?>



I made a new schema in my localhost called testdb, changed the conneciton file you included, updated the databases panel to make sure I had a proper connection, and i do.

Sign in to reply to this post

Morgan

Hi!

Is that the code you get when running the sample?

Or you made some changes?

:)

Took a look at the wa_appbuilder_php.php file looks like its coming from that file, that file is in the webassist folder under database_management. Wierd cos it should be included:
<?php require_once("webassist/database_management/wa_appbuilder_php.php"); ?> and not show up when you looking in a browser.

Update!
Look like i missed some files in the zipping of the sample, so i reupload it. :)
I tryed to run the sample without the missing files, and it worked fine, only thing not showing was the menu. But insert Main Cat and Sub Cat worked fine.
Keep me posted on your progress, :)
/Morgan

Sign in to reply to this post

elevy388997Beta Tester

Ah, there we go. The local version works now except when I try to add a sub category, it says access forbidden with this URL:

http://localhost/sample/%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20variable:%20editFormAction%20in%20%3Cb%3EG:/xampp/htdocs/sample/MainAndSubCat.php%3C/b%3E%20on%20line%20%3Cb%3E251%3C/b%3E%3Cbr%20/%3E



believe it says - Undefinedvariable:editFormAction in
G:/xampp/htdocs/sample/MainAndSubCat.php
On line 251


line 251-

<form class="NewFromBlank_Default" id="Default_NewFromBlank_Default" name="Default_NewFromBlank_Default" method="POST" action="<?php echo $editFormAction; ?>">
Sign in to reply to this post

Morgan

Nice!

hmm, I have after you submit a new Main Cat or New Sub Cat a redirect to $WA_redirectURL = "MainAndSubCat.php";

Try remove the redirect or redirect to a empty page with a back link, see if that solve the forbidden error.

I did the redirect so you could see the changes direct after inserting a new Category. :)

Update!
Remove: action="<?php echo $editFormAction; ?>"

I think its a bit of left over code from an alterd insert of a modyfied field in Form Builder. :)

//Morgan

Sign in to reply to this post

elevy388997Beta Tester

I am pretty close to achieving what you have supplied, but upon testing I get this error after creating the two insert records for the main and sub category submit buttons:


Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in D:\hosting\9062558\html\v2\admin\category_manage.php on line 93

Line 93:

mysql_select_db($WA_connectionDB, $WA_connection)



Update!
_________________
Figured out that at some points I chose PowerCMSConnection for the database connection and other times I chose my saved RemoteConnection for the connection. I had to include both connection files in the php page. It's working now!!

Sign in to reply to this post

Morgan

Hi!

Nice to see that you are close now to get it working. :)
Looks like your database cannot be found. Or the connection to the MySQL server doesnt work.

Check the SQL link. :)
------------------------------
Update!

Nice and gratz to get it too work, just saw you mange to get it up and running!


/Morgan

Sign in to reply to this post

elevy388997Beta Tester

One last bit of help. I successfully followed the dynamic menu tutorial for the main product categories, but i cannot seem to get anything to happen with a nested sub category.

Right now it isn't displaying anything but the main categories.

The hierarchy is:

Products (main menu link to be hovered over)
---Main Category (displays main categories)
------Sub Category


When I was making the nested sub categories, my settings were as follows:

New dynamic link
productsubcatefories (table)
SubCategoryName (Label)
SubCategoryID (key)
/products_results.php?SubCategoryID=[SubCategoryID] (link)
SubCategoryMainCategory (Nested Filter)
SubCategoryName (ascending sort)

Update:
-----------
So I added the repeat region to visually see what subcategories are in which main categories and I get this (i only added "Earrings" in main category "Jewelry":

Sub Category: Earrings in Main Cat: Beads
Sub Category: Earrings in Main Cat: Jewelry
Sub Category: Earrings in Main Cat: Tools
Sub Category: Earrings in Main Cat: Step-By-Step Books
Sub Category: Earrings in Main Cat: How-To DVD's

I look in the database via phpmyadmin and the subcategory Earrings has a SubCategroyMainCategoryID of 2, which i then checked, and it is Jewelry.

Sign in to reply to this post

Morgan

Originally Said By: elevy388997
  One last bit of help. I successfully followed the dynamic menu tutorial for the main product categories, but i cannot seem to get anything to happen with a nested sub category.

Right now it isn't displaying anything but the main categories.

The hierarchy is:

Products (main menu link to be hovered over)
---Main Category (displays main categories)
------Sub Category


When I was making the nested sub categories, my settings were as follows:

New dynamic link
productsubcatefories (table)
SubCategoryName (Label)
SubCategoryID (key)
/products_results.php?SubCategoryID=[SubCategoryID] (link)
SubCategoryMainCategory (Nested Filter)
SubCategoryName (ascending sort)

Update:
-----------
So I added the repeat region to visually see what subcategories are in which main categories and I get this (i only added "Earrings" in main category "Jewelry":

Sub Category: Earrings in Main Cat: Beads
Sub Category: Earrings in Main Cat: Jewelry
Sub Category: Earrings in Main Cat: Tools
Sub Category: Earrings in Main Cat: Step-By-Step Books
Sub Category: Earrings in Main Cat: How-To DVD's

I look in the database via phpmyadmin and the subcategory Earrings has a SubCategroyMainCategoryID of 2, which i then checked, and it is Jewelry.  



Okej, :)
So the menu is to show as you typed, then and you have all the 3 tables. Relation made to the product table also?

If i understod it right, when u put in earrings in as a Sub Cat in Main Cat Jewelry, it shows up in all main categories when you put a reapeat region on? But in phpAdmin it just shows 1 for that main cat and thats Jewelry then sub cat Earrings?

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...