xref: /OK3568_Linux_fs/buildroot/board/forlinx/ok3568/fs-overlay/usr/share/matrix-gui-2.0/submenu.php (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1<?php
2/*
3 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 *
6 *  Redistribution and use in source and binary forms, with or without
7 *  modification, are permitted provided that the following conditions
8 *  are met:
9 *
10 *    Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 *
13 *    Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the
16 *    distribution.
17 *
18 *    Neither the name of Texas Instruments Incorporated nor the names of
19 *    its contributors may be used to endorse or promote products derived
20 *    from this software without specific prior written permission.
21 *
22 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34*/
35
36require("helper_functions.php");
37
38$var = read_desktop_file();
39
40if($var==null)
41{
42	echo "Json.txt file is empty or doesn't exist.";
43	return;
44}
45
46$icon_per_col = $_COOKIE["iconGridCol"];
47$icon_per_row = $_COOKIE["iconGridRow"];
48
49$icons_per_page = $icon_per_col * $icon_per_row;
50$current_page = isset($_GET["page"]) == true ? $_GET["page"] : 0;
51
52
53$cell_height=100/$icon_per_row;
54$cell_width=100/$icon_per_col;
55
56//Some parts of the code doesn't set the submenu variable when the user is at the Main Menu which is relected in the "top" variable
57$submenu = isset($_GET["submenu"]) == true ? $_GET["submenu"] : "main_menu" ;
58
59//A value of -1 disables the next/previous page arrow
60$previous_page = ($current_page != 0) ? $current_page - 1 : -1;
61$next_page = (($current_page+1)*$icons_per_page <  count($var[$submenu]["apps"])) ? $current_page + 1 : -1;
62
63//Only enable exit link if your currently not in the main menu
64$enable_main_menu_link = $submenu != "main_menu";
65
66$submenu_entry = get_submenu($var,$submenu);
67
68$menu_title = ($submenu == "main_menu") ? "Forlinx App Launcher v2 p".($current_page+1) : $submenu_entry["Name"]." Submenu p".($current_page+1);
69
70$start_index = $current_page * $icons_per_page;
71$end_index = $start_index + $icons_per_page - 1;
72
73if(count($var[$submenu]["apps"]) - 1 < $end_index)
74	$end_index = count($var[$submenu]["apps"]) - 1;
75?>
76
77<style type="text/css">
78.icons_cell
79{
80	height:<?php echo $cell_height; ?>%;
81	width:<?php echo $cell_width; ?>%;
82}
83</style>
84
85<?php include "menubar.php"; ?>
86
87<table id = "iconlist" >
88
89<?php
90	for($x = 0,$i = $start_index;$x<$icon_per_row;$x++)
91	{
92		echo "<tr>";
93		for($y = 0;$y<$icon_per_col;$y++,$i++)
94		{
95			echo "<td class = 'icons_cell' align = 'center' >";
96
97			if($i<=$end_index)
98			{
99				$current_app = $var[$submenu]["apps"][$i];
100				$img_src = $current_app["Icon"];
101				$app_title = $current_app["Name"];
102				$type = strtolower($current_app["Type"]);
103				$class = "";
104				$disable_link = false;
105				if($type=="directory")
106				{
107					$category = $current_app["Category"];
108					$link = "submenu.php?submenu=$category";
109
110					if(isset($var[$category]["apps"]) == false)
111					{
112						$link = "coming_soon.php?submenu=$category";
113					}
114				}
115				elseif($type=="application")
116				{
117
118					$has_description_page = $current_app["Description_Link"] != -1;
119
120					//This check to see if the application doesn't have a description page. If it doesn't then directly launch the application"
121					if($has_description_page == false)
122					{
123						$link =  "run_script.php?&submenu=".urlencode($submenu)."&app=".urlencode($app_title);
124
125						//Determine if the application is GUI based. If it is then add a class to the link so the javascript code can
126						//manipulate the link if it needs to
127						if($var[$submenu]["apps"][$i]["ProgramType"]=="gui")
128							$class = "class = 'is_gui_app'";
129					}
130					else
131						$link =  "app_description.php?submenu=".urlencode($submenu)."&app=".urlencode($app_title);
132				}
133
134				echo "<a href = '$link' $class><img src= '$img_src' ></a>";
135				echo "<p>$app_title</p>";
136			}
137			echo "</td>";
138		}
139		echo "</tr>";
140	}
141
142echo "</table>";
143?>
144
145<script>
146//Don't launch GUI based application directly if the application is being launched remotely
147//or if the target doesn't have an attached graphic device
148if(client_is_host == false || has_graphics == false)
149{
150	$('.is_gui_app').each(function(index) {
151		var link = $(this).attr("href");
152		var new_link = link.substr(link.indexOf("&submenu="));
153		new_link = "app_description.php?" + new_link;
154		$(this).attr("href",new_link);
155	});
156}
157</script>
158