Documentation in PDF with images is available for download at http://www.gurusistemas.com
www.gurusistemas.com
phpMyMenu 1½ Class
documentation
2006-07-07
Introduction
Author: Gustavo Arcila (tavoarcila at gmail dot com)
Web: http://www.gurusistemas.com
Name: phpMyMenu.inc.php
Description: An easy to use Right click menus generator class
License: GNU General Public License (GPL)
Release Date: May 13th / 2006
Last Update date: July 15th / 2006
Version: 1½
Comments: An innovative and maybe a future standard in web developing, instituted right now in the beta version of a well known free email provider were I found it very useful.
Some web developers think they own the right click blocking it or making menus for the full page, but they never think that sometimes you must Reload an image or maybe the page.
I Think a contextual menu for specific items in a web page can be very useful if you know use it :D
July 15th Updates:
Modified creascript to call onload function... no need to use body() anymore
Added addSeparator function to add single separators between options.
Changed style for creation of div to fix a bug when rendering pgn icon images on IE.
Thanks to Rotten Eye for his updates.
Features:
* Easy menu creation
* Easy menu integration
* Menus can call URL's as well as JavaScript commands
Tested on:
* Server Side:
* php 4.4.2
* php 5.1.1
* Client Side:
* Internet Explorer 6.0
* Mozilla Firefox 1.5
Few Things To Do:
* Apply CSS classes to DIVs instead of style="" statement.
* Replace the proprietary statement OnContextMenu by a non proprietary (even in firefox also works)
If you make any modifications making it better, please let me know to tavoarcila at gmail dot com
Use
It is free for use for any purpose (public domain), though I would prefer it if you retain the notes at the top of the class containing the authorship, and feedback details.
Note that there is no guarantee or warranty, implied or otherwise with this class.
Sorry if my English is not the best… I’m just learning.. ;-)
Initializing the class
require_once("phpMyMenu.inc.php");
$menu = new menuright();
Methods in the Class
fontstyle
Description:
fontstyle(style)
Defines the style of options.
Parameters:
style tags for style (in standard W3C format)
Sample:
$menu -> fontstyle("font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color:#0000aa; font-weight:bold;");
addmenu
Description:
addmenu(name, width, height, useseparator, bordersize, useimages, borderColor,
color, onmouseovercolor, style, $background)
This function creates a definition for a menu, you may add as many menus as you want.
Parameters:
0. name name for menu (act like DIV ID, must be unique per each menu)
1. width defines the width of the div
2. height defines the height of each option in the menu
3. useseparator defines if appear a separator line between each option.
4. bordersize border width for the menu
5. useimages 1= defines if will use icons in the options
0= No images will be used in the options
6. borderColor Border color, Default #C0C0C0
7. color Background color for menu, Default #FFFFFF
8. onmouseovercolor Highlight color for options when mouse is over, Default #EFEFEF
9. style Defines individual style settings for options (in standard W3C format)
A. background Path for background image for icons (even if useimages= 0)
Sample:
$menu->addmenu("main", 180, 22, 1, 1, 1, '#c0c0c0', '#ffffff', '#efefef', '', 'images/blueback.gif' );
$menu->addmenu("basic", 150, 30, 0, 3, 0, '#000000', '#dddddd', '#c0c0c0', '', '' );
$menu->addmenu("php", 100, 25, 1, 1, 0, '#000000', '#efefef', '#CADFF0', '', 'images/grayback.fig' );
additem
Description:
additem(name, displaytext, link, image)
Used to add options to menu
Parameters:
name Name of menu (as defined in addmenu)
displaytext Text to be displayed as option.
link Link to page (if is a javascript command must be preceded by javascript
image Path for icon image to use in the option
Sample:
$menu->additem("main ", "My Home Page", "index.php","images/arrow.jpg");
$menu->additem("main ", "Javascript Option", 'javascript:alert(\' javascript call from menu\')',"");
$menu->additem("main ", "PHP.NET", "http://www.php.net","images/php.png");
$menu->additem("main ", "PHP Classes", "http://www.phpclasses.org","images/phpclasses.png");
$menu->additem("main ", "Google", "http://www.google.com","images/gmail.png");
$menu->additem("main ", "Guru Sistemas", "http://www.gurusistemas.com","");
$menu->additem("basic", "My Home Page", "index.php","images/arrow.jpg");
$menu->additem("basic", "Javascript Option", 'javascript:alert(\'This is another javascript \')',"");
$menu->additem("basic", "Guru Sistemas", "http://www.gurusistemas.com","");
$menu->additem("php", "PHP.NET", "http://www.php.net","images/php.png");
$menu->additem("php", "PHP Classes", "http://www.phpclasses.org","images/phpclasses.png");
This is the output for above samples
addSeparator
Description:
addSeparator(name, Height, Color)
Used to add a separator between options.
Parameters:
name Name of menu (as defined in addmenu)
Height Height for separator, default 1
Color Color for separator, default is borderColor in addMenu
$menu->addSeparator("principal",2,"#FF0000");
creascript
Description:
creascript()
Generate the JavaScript code, must be called between the
… statements.
Parameters: none
Sample:
$menu->creascript();
body
Description:
body()
Generates the necessary code in body in order to run. (Deprecated in version 1½, generated
automatically when you call creascript(), is here just for backward compatibility)
Sample:
body();?>>
creadivs
Description:
creadivs(withform)
generates the divs code, this code must be inside a form if the page doesn’t have a form, the function is capable to create his own form.
Parameters:
withform
0 – Use 0 if the creadivs is called inside a form
1 – Use 1 to let the script generates his own form
Sample:
$menu->creadivs(1);
onclick
Description:
onclick (name, parameters)
Generates the code in the object in which the menu will apear
Parameters:
name Name of menu (as defined in addmenu)
parameters parameters to be passed by the option to the program
Sample:
onclick("basic","");?> align="center">Text with menu |
onclick("main","");?>border="0" src="images/image.gif" width="300" height="90">
onclick("php","");?>>Just a text in a div with right click menu
Sample script
Right click customized menus
Here comes your own process for ADD new row...";
break;
case "edit":
echo "
Here comes your own process for EDIT row with id ".$_GET[id];
break;
case "delete":
echo "
Here comes your own process for DELETE row with id ".$_GET[id];
break;
}
}
// Incluimos el archivo de classe // Include class file
require_once("phpMyMenu.inc.php");
//Creamos la referencia a la clase // Create class reference
$menu = new menuright();
//Definimos la lista de items para cada menú // Define List options for each menu
$style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color:#0000aa; font-weight:bold;";
$menu->addmenu("principal", 180, 22, 1, 1, 1, '#c0c0c0', '#ffffff', '#efefef', '', 'images/blueback.gif' );
$menu->additem("principal", "My Home Page", "index.php","images/arrow.jpg");
$menu->additem("principal", "Javascript Option", 'javascript:alert(\'This is a javascript call \'+parameters+\'from right click menu\')',"");
$menu->addSeparator("principal");
$menu->additem("principal", "PHP.NET", "http://www.php.net","images/php.png");
$menu->additem("principal", "PHP Classes", "http://www.phpclasses.org","images/phpclasses.png");
$menu->addSeparator("principal");
$menu->additem("principal", "Hotmail", "http://www.hotmail.com","");
$menu->additem("principal", "Another Javascript", 'javascript:alert(\'Also javascript functions can be called\')',"");
$menu->additem("principal", "Google", "http://www.google.com","images/gmail.png");
$menu->additem("principal", "G-Mail", "http://www.gmail.com","images/gmail.png");
$menu->addSeparator("principal",2,"#FF0000");
$menu->additem("principal", "Guru Sistemas", "http://www.gurusistemas.com","");
$menu->addmenu("basic1", 150, 30, 0, 3, 0, '#000000', '#dddddd', '#c0c0c0', '', '' );
$menu->additem("basic1", "My Home Page", "index.php","images/arrow.jpg");
$menu->additem("basic1", "Javascript Option", 'javascript:alert(\'This is another javascript call from right click menu\')',"");
$menu->additem("basic1", "Guru Sistemas", "http://www.gurusistemas.com","");
$menu->addmenu("php", 100, 25, 1, 1, 0, '#000000', '#efefef', '#CADFF0', '', 'images/grayback.gif' );
$menu->additem("php", "PHP.NET", "http://www.php.net","images/php.png");
$menu->additem("php", "PHP Classes", "http://www.phpclasses.org","images/phpclasses.png");
$menu->addmenu("g", 80, 16, 0, 13, 1, '#000000', '#efefef', '#CADFF0', '', '' );
$menu->additem("g", "Google", "http://www.google.com","images/gmail.png");
$menu->additem("g", "G-Mail", "http://www.gmail.com","images/gmail.png");
$menu->addmenu("options", 120, 22, 1, 1, 1, '#000000', '#efefef', '#CADFF0', '', 'images/blueback.gif' );
$menu->additem("options", "Add Row", "example1.php?action=add&id=","");
$menu->additem("options", "Edit Row", "example1.php?action=edit&id=","");
$menu->additem("options", "Delete Row", "example1.php?action=delete&id=","");
$menu->creascript(); // Creamos el script // Script Creation
/* - This lines is just for the example work not necesary for the class working */
$serverdb = "localhost"; //Nombre del servidor // Server Name
$userdb = "murano"; // Nombre de usuario // User name
$passworddb= "tester"; // Contraseña // password
$basedb = "phpclasses" ; // Base de Datos // database
$enlace = mysql_connect($serverdb, $userdb, $passworddb) or die(mysql_error());
mysql_select_db($basedb) or die(mysql_error());
/* - This lines is just for the example work not necesary for the class working */
?>
body();?>>
=$menu->creadivs(1); // creamos los DIVs // Create the DIVs ?>
| |
|
|
| onclick("basic1","");?> align="center">Text with menu |
Text without menu |
onclick("g","");?>border="0" src="images/image.gif" width="300" height="90"> |
| Another without Menu |
onclick("php","");?>>Another one with menu Links to PHP |
|
onclick("principal","");?>>Just a text in a div with right click menu
Just a text in a div without right click menu
| ID |
Name (English) |
Nombre (Español) |
Prefix |
onclick("options",$row["id"]);
echo ">";
echo "".$row["id"]." | ";
echo "".$row["name-en"]." | ";
echo "".$row["name-es"]." | ";
echo "".$row["prefix"]." | ";
echo "";
} while ($row = mysql_fetch_array($sql));
}
echo "
";
mysql_close();
?>
---- SQL STRUCTURE OF TABLES USED IN THE SAMPLE ---
CREATE TABLE `countries` (
`id` int(11) NOT NULL auto_increment,
`name-en` varchar(30) default NULL,
`name-es` varchar(30) default NULL,
`prefix` varchar(5) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=177 ;
INSERT INTO `countries` VALUES (1, 'Afghanistan', 'Afghanistán', '93');
INSERT INTO `countries` VALUES (2, 'Albania', 'Albania', '355');
INSERT INTO `countries` VALUES (3, 'Algeria', 'Algeria', '213');
INSERT INTO `countries` VALUES (4, 'Andorra', 'Andorra', '376');
INSERT INTO `countries` VALUES (5, 'Angola', 'Angola', '244');
INSERT INTO `countries` VALUES (6, 'Antigua & Barbuda', 'Antigua & Barbuda', '1268');
INSERT INTO `countries` VALUES (7, 'Argentina', 'Argentina', '54');
INSERT INTO `countries` VALUES (8, 'Armenia', 'Armenia', '374');
INSERT INTO `countries` VALUES (9, 'Aruba', 'Aruba', '297');
INSERT INTO `countries` VALUES (10, 'Australia', 'Australia', '61');
INSERT INTO `countries` VALUES (11, 'Austria', 'Austria', '43');
INSERT INTO `countries` VALUES (12, 'Azerbaijan', 'Azerbaijan', '994');
INSERT INTO `countries` VALUES (13, 'Bahrain', 'Bahrain', '973');
INSERT INTO `countries` VALUES (14, 'Bangladesh', 'Bangladesh', '880');
INSERT INTO `countries` VALUES (15, 'Barbados', 'Barbados', '1246');
INSERT INTO `countries` VALUES (16, 'Belarus', 'Belorusia', '375');
INSERT INTO `countries` VALUES (17, 'Belgium', 'Bélgica', '32');
INSERT INTO `countries` VALUES (18, 'Belize', 'Belice', '501');
INSERT INTO `countries` VALUES (19, 'Benin', 'Benin', '229');
INSERT INTO `countries` VALUES (20, 'Bermuda', 'Bermuda', '1441');
INSERT INTO `countries` VALUES (21, 'Bolivia', 'Bolivia', '591');
INSERT INTO `countries` VALUES (22, 'Bosnia-Herzegovina', 'Bosnia-Herzegovina', '387');
INSERT INTO `countries` VALUES (23, 'Botswana', 'Botswana', '267');
INSERT INTO `countries` VALUES (24, 'Brazil', 'Brasil', '55');
INSERT INTO `countries` VALUES (25, 'Brunei', 'Brunei', '673');
INSERT INTO `countries` VALUES (26, 'Bulgaria', 'Bulgaria', '359');
INSERT INTO `countries` VALUES (27, 'Burkina Faso', 'Burkina Faso', '226');
INSERT INTO `countries` VALUES (28, 'Burundi', 'Burundi', '257');
INSERT INTO `countries` VALUES (29, 'Cambodia', 'Cambodia', '855');
INSERT INTO `countries` VALUES (30, 'Cameroon', 'Camerún', '237');
INSERT INTO `countries` VALUES (31, 'Canada', 'Canadá', '1');
INSERT INTO `countries` VALUES (32, 'Cape Verde', 'Cabo Verde', '238');
INSERT INTO `countries` VALUES (33, 'Cayman Islands', 'Islas Caimán', '1345');
INSERT INTO `countries` VALUES (34, 'Central African Republic', 'Republica Central Africana', '236');
INSERT INTO `countries` VALUES (35, 'Chad', 'Chad', '235');
INSERT INTO `countries` VALUES (36, 'Chile', 'Chile', '56');
INSERT INTO `countries` VALUES (37, 'China', 'China', '86');
INSERT INTO `countries` VALUES (38, 'Colombia', 'Colombia', '57');
--- END OF DOCUMENT ---
www.gurusistemas.com