Zen Cart Logo
Forums / Contribution-Writing Guidelines / Add Admin configuration menu item (again)

Add Admin configuration menu item (again)

Views: 13,384

Results 1 to 14 of 14
02 Mar 2017, 17:55
#1
reetp avatar

reetp

New Zenner

Join Date:
Nov 2008
Posts:
46
Plugin Contributions:
0

Add Admin configuration menu item (again)

I'm trying to update a plugin(not mine) to 1.55 and make it install automatically

I've read this thread:
https://www.zen-cart.com/showthread.php?199251-Adding-a-menu-item-to-the-v1-5-0-admin

And this wiki page:
https://www.zen-cart.com/content.php?327-Adding-a-menu-item-to-the-v1-5-0-admin

And I am still unable to get anything to appear.....

If I run it through a debugger it doesn't even to seem to see any of my files... !

I have the following structure

./my_config_menu.php
Code for the menu which is accessed via the template

./includes/extra_datafiles/my_config_menu_filenames.php

<?php
// 
define('FILENAME_MY_CONFIG_MENU', 'my_config_menu');
?>

./includes/languages/english/extra_definitions/my_config_menu.php

<?php
// 
define('BOX_TOOLS_MY_CONFIG_MENU', 'Social Media Icons');
?>

./includes/languages/english/my_config_menu.php

<?php
// No definitions required
?>

./includes/functions/extra_functions/my_config_menu_functions.php

if (!defined('IS_ADMIN_FLAG')) {
    die('Illegal Access');
}

// If DB entries do not exist

zen_register_page etc

Can someone explain how a new plugin is picked by Zen and where I have fallen flat on my face ? I know it must be stupidly simple - if I could see it read the start of just one file I can step through and work things out.

If I can fix it I'll add it to the plugins section.

Yours, in hope and desperation :-)

B. Rgds
John

02 Mar 2017, 18:05
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Add Admin configuration menu item (again)

Are all files relative to the store root or your admin? Way it looks, it is as if relative to the store root.

03 Mar 2017, 10:42
#4
reetp avatar

reetp

New Zenner

Join Date:
Nov 2008
Posts:
46
Plugin Contributions:
0

Re: Add Admin configuration menu item (again)

mc12345678:

Are all files relative to the store root or your admin? Way it looks, it is as if relative to the store root.

My bad - relative to admin.

03 Mar 2017, 13:28
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Add Admin configuration menu item (again)

Are you trying to add an element to the Configuration menu or are you adding an entire new admin tool?

03 Mar 2017, 15:36
#7
reetp avatar

reetp

New Zenner

Join Date:
Nov 2008
Posts:
46
Plugin Contributions:
0

Re: Add Admin configuration menu item (again)

lat9:

Are you trying to add an element to the Configuration menu or are you adding an entire new admin tool?

I am trying to add a menu item to the configuration menu that has some options that modify something in a template.

It is the Social Media Icons sharing plugin that has not been updated for v1.5x

03 Mar 2017, 15:53
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Add Admin configuration menu item (again)

To create a new configuration-menu "group" as part of your plugin's install, you'll need (at a minimum) two files:

/YOUR_ADMIN/includes/languages/english/extra_definitions/social_media_icons_name.php:

<?php
define ('BOX_SOCIAL_MEDIA_ICONS', 'Social Media Icons');

/YOUR_ADMIN/includes/functions/extra_functions/init_social_media_icons.php

<?php
$configurationGroupTitle = 'Social Media Icons';
$configuration = $db->Execute ("SELECT configuration_group_id FROM " . TABLE_CONFIGURATION_GROUP . " WHERE configuration_group_title = '$configurationGroupTitle' LIMIT 1");
if ($configuration->EOF) {
    $db->Execute("INSERT INTO " . TABLE_CONFIGURATION_GROUP . " 
                 (configuration_group_title, configuration_group_description, sort_order, visible) 
                 VALUES ('$configurationGroupTitle', '$configurationGroupTitle', '1', '1');");
    $cgi = $db->Insert_ID(); 
    $db->Execute ("UPDATE " . TABLE_CONFIGURATION_GROUP . " SET sort_order = $cgi WHERE configuration_group_id = $cgi");
} else {
    $cgi = $configuration->fields['configuration_group_id'];
}

// -----
// Set the various configuration items, the plugin wasn't previously installed.
//
if (!defined ('SOCIAL_MEDIA_ICONS_ENABLED')) {
    $db->Execute ("INSERT INTO " . TABLE_CONFIGURATION . " ( configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, date_added, sort_order, use_function, set_function ) VALUES ( 'Enable Social Media Icons?', 'SOCIAL_MEDIA_ICONS_ENABLED', 'false', 'Enable the social-media icons processing for your store?  Default: <b>false</b>', $cgi, now(), 10, NULL, 'zen_cfg_select_option(array(\'true\', \'false\'),')");


  //-Additional configuration items get added here
}

// -----
// Register the plugin's configuration page for display on the menus.
//
if (!zen_page_key_exists ('configSocialMediaIcons')) {
    zen_register_admin_page ('configSocialMediaIcons', 'BOX_SOCIAL_MEDIA_ICONS', 'FILENAME_CONFIGURATION', "gID=$cgi", 'configuration', 'Y', $cgi);
}
07 Mar 2017, 01:26
#9
reetp avatar

reetp

New Zenner

Join Date:
Nov 2008
Posts:
46
Plugin Contributions:
0

Re: Add Admin configuration menu item (again)

Bingo ! Well, more or less :-)

Thank - you. I finally got my head around it I think - I have a menu item with config items on the page.

I'll write it up tomorrow. One question.

social_media_icons.filenames.php

What does it do ?

Currently I have something like this but I think it is wrong ?

<?php
define('FILENAME_SOCIAL_MEDIA_ICONS', 'social_media_icons');
?>

B. Rgds
John

07 Mar 2017, 11:53
#10
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Add Admin configuration menu item (again)

@reetp, since you are adding only to configuration elements, that filename is not needed.

It's used if you are providing a new, separate, tool/item for the admin processing and defines the file name (no .php extension) that is associated with your new tool and is used in the tool's admin-page registration.

07 Mar 2017, 15:53
#11
reetp avatar

reetp

New Zenner

Join Date:
Nov 2008
Posts:
46
Plugin Contributions:
0

Re: Add Admin configuration menu item (again)

lat9:

@reetp, since you are adding only to configuration elements, that filename is not needed.

It's used if you are providing a new, separate, tool/item for the admin processing and defines the file name (no .php extension) that is associated with your new tool and is used in the tool's admin-page registration.

OK - got that thank you.

One last....$zco_notify

The old code had a line like this for notifying a clean install (though I am not sure if it actually worked)

    $zco_notifier->notify('SOCIAL_MEDIA_EXTRA_FUNCTIONS_INSTALL_END', array('group_id' => $group_id));

I was wondering about a good install/failed install for the logs e.g.

global $db, $zco_notifier;
$project = PROJECT_VERSION_MAJOR . '.' . PROJECT_VERSION_MINOR;
// Are we a supported version ?
if (PROJECT_VERSION_MAJOR > '1' || PROJECT_VERSION_MINOR >= '5.5') {
    // Do some stuff
    // Notify a good install
    $zco_notifier->notify('SOCIAL_MEDIA_EXTRA_FUNCTIONS_INSTALL_END', array('group_id' => $group_id));
} else {
    // Notify a Failed installed
    $zco_notifier->notify('SOCIAL_MEDIA_EXTRA_FUNCTIONS_INSTALL_FAIL', ' Version Fail < 1.5 :- ' . $project);

}

Is this correct syntax ?

Where do I define the notifys? I thought possibly in admin/includes/languages/english/extra_definitions/social_media_icons.php but I wasn't sure.

B. Rgds
John

07 Mar 2017, 17:19
#12
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Add Admin configuration menu item (again)

reetp:

OK - got that thank you.

One last....$zco_notify

The old code had a line like this for notifying a clean install (though I am not sure if it actually worked)

$zco_notifier->notify('SOCIAL_MEDIA_EXTRA_FUNCTIONS_INSTALL_END', array('group_id' => $group_id));
> 
> I was wondering about a good install/failed install for the logs e.g.
> 
> ```
global $db, $zco_notifier;
$project = PROJECT_VERSION_MAJOR . '.' . PROJECT_VERSION_MINOR;
// Are we a supported version ?
if (PROJECT_VERSION_MAJOR > '1' || PROJECT_VERSION_MINOR >= '5.5') {
    // Do some stuff
    // Notify a good install
    $zco_notifier->notify('SOCIAL_MEDIA_EXTRA_FUNCTIONS_INSTALL_END', array('group_id' => $group_id));
} else {
    // Notify a Failed installed
    $zco_notifier->notify('SOCIAL_MEDIA_EXTRA_FUNCTIONS_INSTALL_FAIL', ' Version Fail < 1.5 :- ' . $project);

}

Is this correct syntax ?

Where do I define the notifys? I thought possibly in admin/includes/languages/english/extra_definitions/social_media_icons.php but I wasn't sure.

B. Rgds
John
$zco_notify type actions are ZC internal "gosub" callers. They tell the internal system: I am here, if you are listening (observer) then do whatever you do when you know I have gotten to this point.

It can be used to provide some sort of standard "I'm done" type notification, but there are other ways to target that type of reaction as well, can use the messageStack to display a message, can make an admin log entry (suggested for PCI compliance) to identify a change in the database, etc...

A notifier/observer pair as coded above is good for repeated work/incorporation of other actions, data changes, database manipulation, etc...

07 Mar 2017, 21:01
#13
reetp avatar

reetp

New Zenner

Join Date:
Nov 2008
Posts:
46
Plugin Contributions:
0

Re: Add Admin configuration menu item (again)

mc12345678:

It can be used to provide some sort of standard "I'm done" type notification, but there are other ways to target that type of reaction as well, can use the messageStack to display a message, can make an admin log entry (suggested for PCI compliance) to identify a change in the database, etc...

Ahhh OK thanks. I was trying to get a log entry.

Being totally dense and a 'non-coder' i.e. amateur hack can you give me a rough idea of how you get a log entry or point me to some docs on the subject?

B. Rgds
John

07 Mar 2017, 21:45
#14
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Add Admin configuration menu item (again)

reetp:

Ahhh OK thanks. I was trying to get a log entry.

Being totally dense and a 'non-coder' i.e. amateur hack can you give me a rough idea of how you get a log entry or point me to some docs on the subject?

B. Rgds
John

So the operations are covered under the three classes related to event logging in admin/includes/classes, but a generic function that works with ZC 1.5.3 (I think or its 1.5.4 can't recall) and above without any additional code (there is a plugin by lat9 that supports backwards compatibility to 1.5.0 and above).

zen_record_admin_activity('my message to log.', 'warning');

That is an example with a warning style entry, but the others are covered in at least one of the three classes.

Pretty much can look for anywhere in the admin that say a customer's data is modified, or a sales record is modified for an example.