forked from rogermoka/Timesheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.CommandMenu.php
133 lines (113 loc) · 2.96 KB
/
class.CommandMenu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Abstract class Command representing a command in a command menu
*/
class Command {
var $text;
var $enabled;
function Command($text, $enabled) {
$this->text = str_replace(" ", " ", $text);
$this->enabled = $enabled;
}
function toString() {
if (!$this->enabled)
return "<span class=\"command_current\">$this->text</span>";
else
return $this->text;
}
function setEnabled($enabled) {
$this->enabled = $enabled;
}
}
/* A class which represents a single command in a command menu.
* It has a url and a visual reprenstation (text)
*/
class TextCommand extends Command {
var $url;
/**
* Constructor
*/
function TextCommand($text, $enabled, $url) {
parent::Command($text, $enabled);
$this->url = $url;
}
function toString() {
if (!$this->enabled)
return parent::toString();
else
return "<a href=\"" . $this->url . "\" class=\"command\">" . $this->text . "</a>";
}
}
class IconTextCommand extends TextCommand {
var $img;
/**
* Constructor
*/
function IconTextCommand($text, $enabled, $url, $img) {
parent::TextCommand($text, $enabled, $url);
$this->img = $img;
}
function toString() {
if (true)
return parent::toString();
else
return "<img src=\"" . $this->img . "\" align=\"absbottom\">" . parent::toString();
}
}
/* A class representing a menu of commands.
* It's responsible for printing the menu with a separator
*/
class CommandMenu {
//array which holds the commands in the menu
var $commands = array();
/* adds a command to the menu */
function add($command) {
$this->commands[] = $command;
}
/* returns the command menu as html */
function toString() {
$printedFirstCommand = false;
$returnString = "";
//iterate through commands
$count = count($this->commands);
for ($i=0; $i < $count; $i++) {
//only print the separator after printing the first command
if ($printedFirstCommand)
$returnString = $returnString . " ";
else
$printedFirstCommand = true;
//append this command to the string
$returnString = $returnString . $this->commands[$i]->toString();
}
//return the command menu as a string
return $returnString;
}
/**
* Disables a menu command with the given text
*/
function disableCommand($text) {
//iterate through commands
$count = count($this->commands);
for ($i=0; $i < $count; $i++) {
if ($this->commands[$i]->text == $text)
$this->commands[$i]->setEnabled(false);
}
}
function disableSelf() {
//iterate through commands
$count = count($this->commands);
for ($i=0; $i < $count; $i++) {
$self = $_SERVER["PHP_SELF"];
$slashPos = strrpos($self, "/");
if (!is_bool($slashPos))
$self = substr($self, $slashPos + 1);
$url = $this->commands[$i]->url;
$pos = strpos($url, $self);
if (!is_bool($pos) && $pos == 0)
$this->commands[$i]->setEnabled(false);
}
}
}
//create the command menu object so that those files which include this one dont need to
$commandMenu = new CommandMenu;
?>