<% use inspui::cmn; my (#$miscargs, #this is passed since no metapage is loaded for this tiny window with SELECT in it.
    $cfgref,$nointro,$is_small_layout,$btn_urls) = @_; 

    #my $sfx = '  - - - - - -  ';
    my $sfx = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

    @$btn_urls = ('/','/','/');
%>

<% my $jsstuffdir = "/stunnix-websrv-inspector/res/js/libs"; 
#now let's load jquery
%>
<link rel="stylesheet" href="<%= $jsstuffdir %>/css/eggplant/jquery-ui-1.10.3.custom.css" />
<script src="<%= $jsstuffdir %>/js/jquery-1.9.1.js"></script> 
<script src="<%= $jsstuffdir %>/js/jquery-ui-1.10.3.custom.js"></script> 
<script src="<%= $jsstuffdir %>/js/jquery.blockUI.js"></script> 
<script src=/stunnix-websrv-inspector/res/funcs.js></script>


<%  $forge->include('insp-piece-mysql-data-not-copied-part',$cfgref,$nointro) %>
<%  $forge->include('insp-piece-mysql-data-prev-version-part',$cfgref,$nointro) %>

<form id=f1 action=/ method=post><input type=hidden name=v1 value=1>
<input type=hidden name=smalllayout value=<%$ (0+$is_small_layout) %> >
</form>
<script language=javascript>
<!--
var actions=[];
function separator_cb() {};
if (!<%$ (0+$nointro)%> && 0) {
    alert("<%$
    __("Stunnix Web Server Inspector has been started; it's a tool that lets you inspect your site and control it and database server. To disable it in newly-created project, go to Project, Site Settings, go to 'General','Main Properties' and uncheck chechbox 'Enable Webserver Inspector'.");
%>");
};
function open_newwnd(url,name,type) 
{
    if (!window.open(url,name, type == 'naked' ? 
	('directories=0,location=0,menubar=0,personalbar=0,height=400' +
        'toolbar=0,resizable=1,status=0,scrollbars=1') : '')) {
	winopen_fallback(url);
    }
}
function open_url_nownd(url) 
{
    f = document.getElementById('f1');
    f.action = url;
    f.submit();
};


actions[0] == separator_cb;
<%
{
our $opt_text = '';#can't  make it my for some reason!!
my $cur_idx = 1;
my $in_optgroup = 0;
sub op
{
    #If only title is given, then it's separator (title defines category)
    #%opts can contain keys: 
    #	'type'=>('none'|'naked'|'normal'),	'name',$window_name #absent if type=none
    my ($title,$url,%opts) = @_;
    if (length($url)) {
%>
    actions[actions.length] = function() {
    <%$
	length($url) ? (
	    $opts{type} eq 'none' ? "  open_url_nownd('$url')" : 
	    $opts{type} =~ /naked|normal/ ? "  open_newwnd('$url','$opts{name}','$opts{type}')" :
		$url
	) : 'separator_cb'
    %>};
<%

    }
    if (!length($url)) {
	$opt_text .= "\n</optgroup>" if $in_optgroup;
	$opt_text .= "\n\n<optgroup label=\"" . $tf->escape_html($title) . "\">";
	$in_optgroup = 1;
    } else {
	$opt_text .= "\n" . '<option>' .  $tf->escape_html($title) . "</option>";
    };
    #$title =  $sfx. $title . $sfx if !length($url);
    #$opt_text .= "\n" . '<option>' .  $tf->escape_html($title);
}

sub opui { my ($title,$url,%opts) = @_; op($title, '/stunnix-websrv-inspector/insp-ui/inspui.xpl/none/'.$url,  %opts); };

sub oputil { my ($title,$url,%opts) = @_; 
    my $realurl = ( ($^O =~ /win32/i && $url !~ /^browse/ ) ?  '/stunnix-websrv-inspector/insputil.exe?op='
	:'/stunnix-websrv-inspector/insp-ui/inspui.xpl/none/misc.' ).$url;
    $realurl .= '?smalllayout=' . ($is_small_layout+0) 
		if ($realurl =~ /inspui.xpl/);
    return $realurl if $opts{givemeurl};
    op($title, $realurl, %opts); 
};

    my $is_saws =  $cfgref->{product}->{apache_based};    
    my $has_mysql = $ENV{MYSQL_PORT};

    opui(__('About this tool'),qw(misc.about type naked name _about));

    op(__('Most used operations'));
    {
	my $fm = 'file manager';
	$fm = 'Explorer' if $^O =~ /win32/i;
	$fm = 'Finder' if $^O =~ /darwin/i;    
	oputil( sprintf(__('Open document root in %s'), $fm), qw(browsedocdir type none));
    }
    
    if ($has_mysql) {
	my $path = '/stunnix-websrv-inspector/phpmyadmin/';
	$path = '/stunnix-websrv-inspector/phpmyadmin3/' if 
	    ($cfgref->{server_info}->{mysql}->{bindir} =~ /mysql5/ && #we have mysql5
		(	
		    ( $cfgref->{server_info}->{ALL}->{_httpd_defines}->{HAVE_MODPHP5} || 
			$cfgref->{server_info}->{ALL}->{_httpd_defines}->{HAVE_MODPHP7} ) &&		    	
		    $cfgref->{server_info}->{ALL}->{_modphp5_so_path} !~ /modphpphp5-/ #exclude php5.0!		        
		)
    
	    );
	$btn_urls->[1] = $path;
	op(__('Browse MySQL database with phpMyAdmin'),$path,qw(
		 type normal name _phpmyadmin)) if $ENV{MYSQL_PORT};
    };

    op(__('Open website'),$cfgref->{server_info}->{ALL}->{urlpath},qw(type normal));



    op(__('Server logs and state'));


    #opui(__('Webserver access log in pretty form'),
    #	qw(viewfile.prettyaccesslog naked _prettyacclog));
    opui(__('Webserver error log'),qw(viewfile.rawerrorlog type naked name _rawerrlog));
    opui(__('Webserver access log (raw form)'),qw(viewfile.rawaccesslog type naked name _rawaccesslog));
    op(  __('See output of phpinfo()'),'/stunnix-websrv-inspector/show-phpinfo.php',qw(type normal name _phpinfo));

    opui(__('View web server properties (available as JSON to client-side and server-side scripts)'),
	qw(viewfile.status type naked name _status));
    opui(__('View environment variables available to serverside scripts'),qw(viewfile.envs type naked name _envs));
    if ($has_mysql) {
	opui(__('View MySQL server log'),qw(viewfile.mysqllog type naked name _mysqllog));
    };



    #if ($^O =~ /win32/i || $^O =~ /darwin/ ) 
    {
	op(__('Browsing aux directories'));
	oputil(__('Open directory for permanent site\'s files'),qw(browsepermdir type none));
	oputil(__('Open directory with temporary webserver and database files'),
	    qw(browsetmpstatedir type none));
    }


    op(__('Stopping/Restarting'));
    op(__('Stop Prototype'),
	    $is_saws ?
	    '/stop-the-server/helper-stop-httpd.exe' : '/spws-terminate-and-release-cd.html',
		 qw(type naked name _phpmyadmin));
    op(__('Restart Prototype'),	qw(restart_webserver() type ajax)) 
	if $is_saws ;
    op(__('Reset all state and restart Prototype (simulates running Prototype on this computer for the first time)'),
		qw(reset_state_and_restart_webserver() type ajax)) 
	if $is_saws ;

    oputil(__('Restart web server only'),qw(restartwebsrv type none)) if $is_saws;
    oputil(__('Stop mysql server only'),qw(stopmysql type none)) if $has_mysql;

    {
	$btn_urls->[2] = $cfgref->{server_info}->{ALL}->{urlpath};
	$btn_urls->[0] = oputil('this arg is ignored',qw(browsedocdir type none givemeurl 1));
    }
%>
var select_constructed = 0;
function opselector_onchange(obj)
{
    var idx = obj.selectedIndex;
    //if (idx!=1)
	actions[idx-1]();
    if (select_constructed)
	obj.selectedIndex = 0;
}
-->
</script>



<% if ($is_small_layout) { %>

    <div style='margin-left:1em;margin-right:1em;'><center>
    <select id=s1 name=opselector  onchange='opselector_onchange(this)' >
    <option ><%$     ($sfx . __('Select the action to perform') . $sfx); %>
        <%$     $opt_text;  %></optgroup>
    </select></center>
    </div>


<% } else  { #not small layout %>

    <select id=dropdown name=opselector  onchange='opselector_onchange(this)' >
    <option ><%$     ($sfx . __('Select the action to perform') . $sfx); %>
	<%$     $opt_text;  %></optgroup>
    </select>

<% } #end of not small layout %>


<script language=javascript>
<!--
    select_constructed =1;
-->
</script>
<% 
}  #end of megablock of code
%>


<div id="open_link_dlg" style="display:none" title="Popup blocker detected" >
<p>
Your browser blocks popup windows. Please click <a id=open_link_dlg_href target=_blank href=>here</a> 
to open it in new tab.
<p>
</p>
</div>

<script>

function winopen_fallback(url) {
	\$('#open_link_dlg_href').attr('href',url);

        \$( "#open_link_dlg" ).dialog(
                {
                        modal: true,
                        buttons: {
                                Ok: function() {
                                        \$( this ).dialog( "close" );
                                        }
                        }
                }
        ).dialog("option", "width", "500");
};

</script>
