SQL Query check

Working on a freebie mod for everyone right now.  My first toy in D7 that will be public, just want to make sure I have the SQL correct for inserting an item into the Admin Menu.  (This is to go into tools.)  If a couple of you SQL gurus can give this a once over I'd appreciate it.  Hoping by morning to have this out to everyone.

 

INSERT INTO `sys_menu_admin` (`id`, `parent_id`, `name`, `title`, `url`, `description`, `icon`, `icon_large`, `check`, `order`) VALUES ('', '4', 'FAQ MGR', '_faq_mgr', '{siteAdminUrl}faq.php', 'Manage your FAQs from this page.', 'faq.gif', '', '', '');

 

If it has a problem please let me know so it can be fixed.  The server executed it perfectly and it's appearing in the menu where I wanted it, just making sure it works.  Also, does anyone know how I can get the DB to assign it an Order in the menu?  Right now it just defaults it to "0" as the order.

Thanks in advance.

Quote · 2 Apr 2010

To set the order for example the last item you can set a variable.

SET @iOrder = (SELECT MAX(`order`) FROM `sys_menu_admin` WHERE `parent_id` = '4');

Then your query. Because ID is auto incremented, you don't need to include it. I also left `Check` and icon_large out as they will default to null.

INSERT INTO `sys_menu_admin` (`parent_id`, `name`, `title`, `url`, `description`, `icon`,`order`) VALUES ('4', 'FAQ MGR', '_faq_mgr', '{siteAdminUrl}faq.php', 'Manage your FAQs from this page.', 'faq.gif',@iMax+1);

So this in a sql file should work inserting it as the last item in order.

SET @iOrder = (SELECT MAX(`order`) FROM `sys_menu_admin` WHERE `parent_id` = '4');
INSERT INTO `sys_menu_admin` (`parent_id`, `name`, `title`, `url`, `description`, `icon`, `icon_large`,`order`) VALUES ('4', 'FAQ MGR', '_faq_mgr', '{siteAdminUrl}faq.php', 'Manage your FAQs from this page.', 'faq.gif',@iOrder+1);

https://www.deanbassett.com
Quote · 2 Apr 2010

Thanks Deano, that is a huge help.  And it makes sense with the explanation. 

 

Now if I could just get the pages in the Admin Panel to throw up the Header/Footer/Menu like they should.  Amazing, I have a functioning page just missing all the normal stuff.  LOL. 

Working on it, but if you have something to toss out folks it'd be greatly appreciated.  This dang thing works except for the headers & footers.  Keeps yelling about inc/classes/BxDolTemplates.php.  Gawd do I hate Dolphin some days.

Quote · 2 Apr 2010

Is this for D6 of D7?

Based on your query it looks like your putting a faq.php file in the admin directory. D6 methods instead of putting the entire thing inside a D7 module.

https://www.deanbassett.com
Quote · 2 Apr 2010

 

Is this for D6 of D7?

Based on your query it looks like your putting a faq.php file in the admin directory. D6 methods instead of putting the entire thing inside a D7 module.

 

 

This is for D7.  Trying to learn the D7 method for doing things and yes as I'm learning I started with what I know.  Here's the full file for the admin page.  It's just not being nice to me.  Specifically it's just an FAQ Manager, didn't think it really needed an entire module all for itself but I'm probably wrong the way it looks that D7 is acting on this.

 


<?

define('BX_SECURITY_EXCEPTIONS', true);
$aBxSecurityExcepti alt= array(
    'POST.body',
    'REQUEST.body',
);

require_once( '../inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'prof.inc.php' );

bx_import('BxTemplFormView');
bx_import('BxDolEmailTemplates');

$logged['admin'] = member_auth( 1 );
$_page['css_name'] = 'faq.css';

check_logged();

if( !$demo_mode && 'add' == $_GET['action'] )
{
 echo GetFaqForm();
}
elseif( !$demo_mode && 'addnew' == $_POST['action'])
{
 if( 1 > strlen($_POST['title']) )
 {
  echo GetActionText( 'Please enter question' );
  echo GetFaqForm( false, 0, true );

 }
 


 elseif( 1 > strlen($_POST['desc']) )
 {
  echo GetActionText( 'Please enter answer' );
  echo GetFaqForm( false, 0, true );
 }
 else
 {
  if( db_res( "INSERT INTO `faq` SET `Title` = '" . $_POST['title'] . "', `Description` = '" . $_POST['desc'] . "';" ) )
  {
  echo GetActionText( 'question successfully added', 1);
  echo GetFaqList();
  }
  else
  {
  echo GetActionText( 'action failed');
  echo GetFaqList();
  }
 }

}
elseif( !$demo_mode && 'edit' == $_GET['action'])
{
 echo GetFaqForm( true, $_GET['faqID'] );
}
elseif( !$demo_mode && 'update' == $_POST['action'] )
{
 if( 1 > strlen($_POST['title']) )
 {
  echo GetActionText( 'Please enter Question' );
  echo GetFaqForm( false, 0, true );

 }
 


 elseif( 1 > strlen($_POST['desc']) )
 {
  echo GetActionText( 'Please enter Answer' );
  echo GetFaqForm( false, 0, true );
 }
 else
 {
  if( db_res( "UPDATE `faq` SET `Title` = '" . process_db_input($_POST['title']) . "', `Description` = '" . process_db_input($_POST['desc']) . "' WHERE `ID` = " . (int)$_POST['faqID'] . ";" ) )
  {
  echo GetActionText( 'question updated successfully', 1 );
  echo GetFaqList();
  }
  else
  {
  echo GetActionText( 'action failed');
  echo GetFaqList();
  }
 }
}
elseif( !$demo_mode && 'delete' == $_GET['action'] )
{
 if( db_res( "DELETE FROM `faq` WHERE `ID` = " . (int)$_GET['faqID'] ) )
 {
  echo GetActionText( 'question deleted successfully', 1 );
  echo GetFaqList();
 }
 else
 {
  echo GetActionText( 'action failed');
  echo GetFaqList();
 }
}
else
{
 echo GetFaqList();
}

ContentBlockFoot();
BottomCode();

function GetFaqList()
{
 global $site;

$faq_query = "SELECT `ID`, `Title`, `Description` FROM `faq` ORDER BY ID DESC";
 $faq_res = db_res($faq_query);

 $faq_count = db_arr("SELECT COUNT(ID) FROM `faq`");
 $faq_count = $faq_count['0'];
 $faqs_ alt= 10;

 $ret = '';
 $ret .= '<div class="faqAdd">';
 $ret .= '<a href="' . $site['url_admin'] . 'faq.php?action=add">';
  $ret .= 'Add New Question';
  $ret .= '</a>';
 $ret .= '</div>';
 $j = 1;
 while( $faq_arr = mysql_fetch_assoc($faq_res))
 {
  if( ($j%2) == 0 )
  {
  $add = 'style="background-color:#E6E6E6;"';
  }
  else
  {
  $add = '';
  }

  $ret .= '<div class="faq_block" ' . $add . '>';
  $ret .= '<div class="faq_title">';
  $ret .= process_line_output($faq_arr['Title']);
   $ret .= '</div>';
   $ret .= '<div>';
  $ret .= process_html_output($faq_arr['Description']);
   $ret .= '</div>';
   $ret .= '<div style="text-align:right;">';
$ret .= '<a href="' . $site['url_admin']  . 'faq.php?faqID=' . $faq_arr['ID'] . '&action=edit">';
     $ret .= 'Edit';
    $ret .= '</a>';
    $ret .= '&nbsp;||&nbsp;';
 $ret .= '<a href="' . $site['url_admin']  . 'faq.php?faqID=' . $faq_arr['ID'] . '&action=delete">';
     $ret .= 'Delete';
    $ret .= '</a>';
   $ret .= '</div>';
  $ret .= '</div>';

  $j++;
 }

 return $ret;
}

function GetFaqForm( $edit = false, $faqID = 0, $use_post_data = false )
{
 global $site;

 $ret = '';
 if( $edit )
 {
  $faq_arr = db_arr( "SELECT `ID`, `Title`, `Description` FROM `faq` WHERE `ID` = '" . (int)$faqID . "';");
  $value_title = htmlspecialchars($faq_arr['Title']);
  

  $value_desc = htmlspecialchars($faq_arr['Description']);
 }
 elseif( $use_post_data )
 {
 $value_title = htmlspecialchars( process_pass_data($_POST['title']) );
 

 $value_desc = htmlspecialchars( process_pass_data($_POST['desc']) );
 }
 else
 {
  $value_title = '';
  

  $value_desc = '';
 }


 $ret .= '<div class="faq_block">';
$ret .= '<form action="' . $site['url_admin'] . 'faq.php" method="post">';
$ret .= '<table cellpadding="0" cellspacing="1" border="0" width="70%" align="center">';
  $ret .= '<tr>';
  $ret .= '<td>';
   $ret .= 'Question';
  $ret .= '</td>';
  $ret .= '<td>';
$ret .= '<input type="text" class="faq_text_input" name="title" value="' . $value_title . '" />';
  $ret .= '</td>';
  $ret .= '</tr>';
    
                                $ret .= '<tr>';
  $ret .= '<td>';
                  $ret .= 'Answer';
  $ret .= '</td>';
  $ret .= '<td>';
      $ret .= '<textarea name="desc" class="faq_textarea">' . $value_desc  . '</textarea>';
  $ret .= '</td>';
  $ret .= '</tr>';
  $ret .= '<tr>';
  $ret .= '<td colspan="2" align="center">';
     if( $edit )
     {
 $ret .= '<input type="hidden" name="faqID" value="' . $faqID . '">';
 $ret .= '<input type="hidden" name="action" value="update">';
     }
     else
     {
 $ret .= '<input type="hidden" name="action" value="addnew">';
     }

 $ret .= '<input type="submit" value="Save" />';
     $ret .= '</td>';

    $ret .= '</tr>';
$ret .= '<tr>';
$ret .= '<td>';
$ret .= '</td>';
$ret .= '<td>';
$ret .= '<div style="position:relative; text-align:left; font-weight:bold;">';
$ret .= '<a href="' . $site['url_admin'] . 'faq.php">Back to FAQ list</a>';
$ret .= '</div>';
$ret .= '</td>';
$ret .= '</tr>';


   $ret .= '</table>';
  $ret .= '';
 $ret .= '</div>';
 return $ret;
}

function GetActionText( $text, $success = '')
{
 global $site;

 $ret = '';
 if( $success )
 {
  $ret .= '<div style="position:relative; border:1px solid green; margin-bottom:20px; font-weight:bold; text-align:center; color:green; padding:3px;">';
//$ret .= '<div style="font-weight:bold; text-align:center; color:green;">';
    $ret .= $text;
   //$ret .= '</div>';
  $ret .= '</div>';


/*
  $ret .= '<div style="position:relative; text-align:center;">';
   $ret .= '<a href="' . $site['url_admin'] . 'faq.php">Back to FAQ list</a>';
  $ret .= '</div>';

*/

 }
 else
 {
  $ret .= '<div style="position:relative; border:1px solid red; margin-bottom:20px; font-weight:bold; text-align:center; color:red; padding:3px;">';
 $ret .= '<div style="font-weight:bold; text-align:center; color:red;">';
  $ret .= $text;
  $ret .= '</div>';
  $ret .= '</div>';
/*  $ret .= '<div style="position:relative; text-align:center;">';
$ret .= '<a href="' . $site['url_admin'] . 'faq.php">Back to FAQ list</a>';
  $ret .= '</div>';
*/
 }

 return $ret;

}

?>


The system works, I'm just not figuring out the part that gets the full Admin Page to resolve like it should.  But yeah, I'm using what I learned in D6 for this.  Big mistake I'm guessing.

Quote · 2 Apr 2010

I'll take a peek at the code. Even though it might end up competing with mine. http://www.boonex.com/unity/extensions/entry/FAQ_Page_Editor_for_Dolphin_7_0


But converting it to a D7 module should not be too hard either. Have you looked at the bloggie example yet? You should find it helpful. I wish it was there when i started learning modules. http://www.boonex.com/trac/dolphin/wiki/DolphinTutorialMyFirstModule

I'll play with it when i get a chance. See if i can find the problem.

https://www.deanbassett.com
Quote · 2 Apr 2010

 

I'll take a peek at the code. Even though it might end up competing with mine. http://www.boonex.com/unity/extensions/entry/FAQ_Page_Editor_for_Dolphin_7_0


But converting it to a D7 module should not be too hard either. Have you looked at the bloggie example yet? You should find it helpful. I wish it was there when i started learning modules. http://www.boonex.com/trac/dolphin/wiki/DolphinTutorialMyFirstModule

I'll play with it when i get a chance. See if i can find the problem.

 

 

 Mine isn't as fancy as yours.  What with those multiple languages and all of that in it.  Look at mine as the simple version of yours and it has a couple other items that will come in also when I figure this one out (they all share the same idea and platform as this one).  Don't think they'll compete, mine will just be the free version for those that can't afford yours and I'll keep the options on it down (just adding/editin/deleting of the FAQ's) without the Language Support and such your offering.  That should keep those who complain they can't afford stuff from whining and those who can afford things and want the fancier option can look to yours.

Gawd is yours nice.  I'll pass you over the other ones I'm working on for you to upgrade those for them when they're done, that way we can keep the free ones seperate from the paid and still show how they connect if you like.  Sorry about the competition, didn't realize you had that out already.

 

 

Quote · 2 Apr 2010
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.