<?php

/**
 *
 *
 * @package   mod_loginplus17v13
 * @web www.blackdale.com
 * @Copyright Bob Galway
 * @license GPL3   http://www.gnu.org/licenses/
 */

// no direct access
defined('_JEXEC') or die;

$url = JURI::base();

//collect parameters

//general module properties
$heightout= $params->get('heightout');
$internal = $params->get('internal');
$contentx = "";
$css = "";

$modno = "LP_".($module->id);
$marginleft = $params->get('marginleft');
$marginright = $params->get('marginright');


$paddingleft = $params->get('paddingleft');
$paddingright = $params->get('paddingright');
$paddingtop = $params->get('paddingtop');
$paddingbottom = $params->get('paddingbottom');
$margintop = $params->get('margintop');
$marginbottom = $params->get('marginbottom');
$width = $params->get('modwidth');
$widthunit = $params->get('widthunit');
$colour = $params->get('colour');
$colour1 = $params->get('colour1');
$colour2 = $params->get('colour2');
$fontpx = $params->get('fontpx');
$inputsize = $params->get('inputsize');
$graphics = $params->get('graphics');
$xtracss = $params->get('xtracss');
$customtext = $params->get('customtext');
$starttext = $params->get('starttext');
$endtext = $params->get('endtext');

$username = $params->get('username');
$password = $params->get('password');
$forgotu = $params->get('forgotu');
$forgotp = $params->get('forgotp');
$rememberm = $params->get('rememberme');
$createa = $params->get('createa');
$hiname = $params->get('hiname');
$greet = $params->get('greet');

$menuitemno =  JRequest::getInt('Itemid');
$pageselect=$params->get('pageselect');
if ($pageselect=='2'){$menuitemno = $params->get('menuitem');}
// colours

$keycolour = $params->get('keycolour');
if ($keycolour == "blue")
{
    $bgcolour = '#aabbff';
}
if ($keycolour == "green")
{
    $bgcolour = '#aaffaa';
}
if ($keycolour == "red")
{
    $bgcolour = '#dd2222';
}
if ($keycolour == "orange")
{
    $bgcolour = '#cc9944';
}
if ($keycolour == "yellow")
{
    $bgcolour = '#dd9';
}
if ($keycolour == "purple")
{
    $bgcolour = '#d244f2';
}
if ($keycolour == "grey")
{
    $bgcolour = '#dddddd';
}

$bgcustomcolour = $params->get('bgcustomcolour');
$bgautocolour = $params->get('bgautocolour');
if ($bgautocolour == 2)
{

    $bgcolour = $bgcustomcolour;
}

// css remove feature options

$frem = $params->get('frem');
$fr = $params->get('fr');
$fn = $params->get('fn');
$fp = $params->get('fp');

if (($fr == "none") && ($fn == "none") && ($fp == "none"))
{
    $ul = "display:none;";
    $inputpadding = "padding-bottom:5px;";

}

//modify paths if media libraries available

$surroundstyle = $params->get('surroundstyle');

$surroundpx = substr($surroundstyle,0,2);

if(substr($surroundpx,0,1)==0){$surroundpx=substr($surroundpx,-1,1);}
$surroundpx .="px";
if($surroundstyle !=="custom"){$lib = substr($surroundstyle,-1,1);}


// define possible paths for graphics

$path1 = "modules/mod_bdalemedia1";
$path2 = "modules/mod_bdalemedia2";
$path3 = "modules/mod_bdalemedia3";
$path4 = "modules/mod_bdalebackgrounds";

//Select backgrounds source folder

if (JFolder::exists($path4))
{
    $bgmodulemedia = 'mod_bdalebackgrounds';
} else
{
    $bgmodulemedia = 'mod_loginplus17v13';
}

//Select surrounds source folder

$surmodulemedia = 'mod_loginplus17v13';
if ((JFolder::exists($path1) && ($lib == 1)) || (JFolder::exists($path2) && ($lib ==
    2)) || (JFolder::exists($path3) && ($lib == 3)))
{
    $surmodulemedia = 'mod_bdalemedia' . $lib;
}

// set dimension etc for custom surround
$custompx = $params->get('custompx');
if ($surroundstyle == "custom")
{
    $surroundpx = $custompx;
    $surmodulemedia = 'mod_loginplus17v13';
}

//colours & backgrounds

$bgpattern = $params->get('bgpattern');
if ($bgpattern == "custom")
{
    $bgmodulemedia = 'mod_loginplus17v13';
}

$customcolour = $params->get('customcolour');

if ($bgpattern == "none")
{
    $bguse = 2;
}
if ($bgpattern !== "none")
{
    $bguse = 1;
}

if ($bguse == 1)
{
    $bg = 'background:' . $bgcolour . ' url("' . $url . 'modules/' . $bgmodulemedia .
        '/tmpl/images/backgrounds/' . $bgpattern . '.png")';
}

if ($bguse == 2)
{
    $bg = 'background-color:' . $bgcolour . ';';
}

//Login specific


//button type /height etc
$loginbtn = $params->get('loginbtn');
$btntype = "image";
if ($loginbtn == 1)
{
    $btntype = "submit";
}

$loginbtncolour = $params->get('loginbtncolour');
$btnheight = substr($loginbtn, -2, 2);
$loginbtn = rtrim($loginbtn, "0...9");

//orientation

$orient = $params->get('orient');


// Outputs

if ($surroundstyle == "custom")
{
    $surroundpx = $custompx;
    $surmodulemedia = 'mod_loginplus17v13';
}

//colours & backgrounds

$bgpattern = $params->get('bgpattern');

if ($bgpattern == "custom")
{
    $bgmodulemedia = 'mod_loginplus17v13';
}
$customcolour = $params->get('customcolour');

$bgcustomcolour = $params->get('bgcustomcolour');
$bgautocolour = $params->get('bgautocolour');
if ($bgautocolour == 2)
{

    $bgcolour = $bgcustomcolour;
}

if ($bgpattern == "none")
{
    $bguse = 2;
}

if ($bgpattern !== "none")
{
    $bguse = 1;
}
if ($bguse == 1)
{
    $bg = 'background:' . $bgcolour . ' url("' . $url . 'modules/' . $bgmodulemedia .
        '/tmpl/images/backgrounds/' . $bgpattern . '.png")';
}
if ($bguse == 2)
{
    $bg = 'background-color:' . $bgcolour . ';';

}


//***********************************************************************   Create CSS   ****************************************************************


if ($graphics == 1)
{
    $css = 'td.corner1_' . $modno . '{width:'.$surroundpx.';height:'.$surroundpx.';padding:0;margin:0;background:url(' . $url .
        'modules/' . $surmodulemedia . '/tmpl/images/surrounds/' . $surroundstyle . '/' .
        $keycolour . '/corner1.png) no-repeat ;

}
td.corner2_' . $modno . '{width:'.$surroundpx.';height:'.$surroundpx.';padding:0;margin:0;background:url(' . $url .
        'modules/' . $surmodulemedia . '/tmpl/images/surrounds/' . $surroundstyle . '/' .
        $keycolour . '/corner2.png) no-repeat ;

}
td.corner3_' . $modno . '{width:'.$surroundpx.';height:'.$surroundpx.';padding:0;margin:0;background:url(' . $url .
        'modules/' . $surmodulemedia . '/tmpl/images/surrounds/' . $surroundstyle . '/' .
        $keycolour . '/corner3.png) no-repeat ;

}
td.corner4_' . $modno . '{width:'.$surroundpx.';height:'.$surroundpx.';padding:0;margin:0;background:url(' . $url .
        'modules/' . $surmodulemedia . '/tmpl/images/surrounds/' . $surroundstyle . '/' .
        $keycolour . '/corner4.png) no-repeat ;

}

#contenttable' . $modno .
        '{border-collapse:collapse;border:0px !important;padding:0px !important ;margin:0px !important;overflow:hidden';
    if (!empty($colour1))
    {
        $css .= 'background:' . $colour1 . ';';
    }


    $css .= '}#inner' . $modno . '{padding:3px;' . $bg . ';min-height:'.($btnheight ).'px}
#contenttable' . $modno . ' td, #contenttable' . $modno .
        ' tr{border:0px !important;padding:0px !important ;margin:0px !important;}
        
#contenttable' . $modno . '{width:100%;}';

}
if(!empty($heightout)){$css .='#logout'. $modno .'{min-height:'.$heightout.'px !important;}';}


$css .= 'a.linkx,#modlgn-usernamex,#modlgn-usernamex2, #modlgn-passwdx,#modlgn-passwdx2, .userdatax label{width:'.$inputsize.'px;font-size:'.$fontpx.'px;}
#form-login-rememberx{display:' . $frem . ';}
#form-login-rememberx,#form-login-rememberx tr, #form-login-rememberx td,#logout ,#logout tr,#logout td{background-color:transparent;margin:0px !important;border:0px !important;padding:0px !important ;border-collapse:collapse !important;}
.userdatax {padding:0px;border:0px;margin:0px;}

a.linkx{text-decoration:none;}';



$css .= '.loginplus' . $modno . '{';
if (!empty($margintop))
{
    $css .= 'margin-top:' . $margintop . 'px;';
}
if (!empty($marginbottom))
{
    $css .= 'margin-bottom:' . $marginbottom . 'px;';
}
if (!empty($marginleft))
{
    $css .= 'margin-left:' . $marginleft . 'px;';
}
if (!empty($marginright))
{
    $css .= 'margin-right:' . $marginright . 'px;';
}

if (!empty($paddingtop))
{
    $css .= 'padding-top:' . $paddingtop . 'px;';
}
if (!empty($paddingbottom))
{
    $css .= 'padding-bottom:' . $paddingbottom . 'px;';
}
if (!empty($paddingleft))
{
    $css .= 'padding-left:' . $paddingleft . 'px;';
}
if (!empty($paddingright))
{
    $css .= 'padding-right:' . $paddingright . 'px;';
}
if (!empty($colour1))
{
    $css .= 'background:' . $colour1 . ';';
}



$css .= 'width:' . $width . $widthunit . ';overflow:hidden;}
div.item { padding:0px !important; margin-right:5px;margin-left: 0px !important;margin-top: 0px !important;margin-bottom:0px !important;border:0px !important ;display:inline;}
div.row { padding:4px !important; margin-right:5px;margin-left: 0px !important;margin-top: 0px !important;margin-bottom:0px !important;border:0px !important ;}

#item_btn{float: right;}';




//Add user Styles

$css .= $xtracss;

//add CSS to head section of page

$doc = &JFactory::getDocument();
$doc->addStyleDeclaration($css, 'text/css');


//***********************************************************************Login/Logout forms********************************************************

//logout

$logout = JText::_('BUTTON_LOGOUT');


// vertical
if (($type == 'logout') && ($orient == 2))
{
    $contentx .= '<div id="logout' . $modno . '"><form action="';
    $contentx .= JRoute::_('index.php', true, $params->get('usesecure'));
    $contentx .= '" method="post" id="login-formx">';
    if ($params->get('greeting'))
    {
        $contentx .= '<div class="login-greeting">';
        if ($params->get('name') == 0)
        {
            $contentx .= $hiname."&nbsp; ".($user->get('name'));
        } else
        {
            $contentx .= $hiname."&nbsp; ".($user->get('username'));
        }
        $contentx .= '</div>';
    }

    $contentx .= '<div class="row">

<input  type="' . $btntype .'"  name="Submit" onmouseover="this.style.opacity=.7;" onmouseout="this.style.opacity=1;" class="buttonx" value="' . (JText::_('JLOGOUT')) . '"  src="' . $url . 'modules/mod_loginplus17v13/tmpl/images/buttons/' . $loginbtn . '_logout' . $btnheight . '/' . $loginbtncolour . '.png"/>


		<input type="hidden" name="option" value="com_users" />
		<input type="hidden" name="task" value="user.logout" />
		<input type="hidden" name="return" value="' . ($return) . '" />' . (JHtml::_('form.token')) .
        '</div>
		</form><div>' . $customtext . '</div></div>';
}

//horizontal

if (($type == 'logout') && ($orient == 1))
{
    $contentx .= '<table style="border:0 !important;border-collapse:collapse;width:100%" summary="logout"  id="logout' . $modno .  '" >
    <tr style="border:0 !important;">
    <td style="border:0 !important;">';
    if ($params->get('greeting'))
    {
        $contentx .= '<span class="login-greeting" style="float:left;">';
        if ($params->get('name') == 0)
        {
            $contentx .= $hiname."&nbsp; ".($user->get('name'));
        } else
        {
            $contentx .= $hiname."&nbsp; ".($user->get('username'));
        }
        $contentx .= '</span>';
    }
    
    if (!empty($customtext)){$contentx .=  '<span >' . $customtext . '</span>';}
  
     $contentx .= '</td>';
    $contentx .='<td style="border:0 !important;"><form style="float:right;"  action="'; $contentx .= JRoute::_('index.php', true, $params->get('usesecure')).'" method="post" id="login-formx"> 

<input  type="' . $btntype . '"  name="Submit" onmouseover="this.style.opacity=.7;" onmouseout="this.style.opacity=1;" class="buttonx" value="' . (JText:: _('JLOGOUT')) . '"  src="' . $url . 'modules/mod_loginplus17v13/tmpl/images/buttons/' . $loginbtn . '_logout' . $btnheight . '/' . $loginbtncolour . '.png"/>


		<input type="hidden" name="option" value="com_users" />
		<input type="hidden" name="task" value="user.logout" />
		<input type="hidden" name="return" value="' . ($return) . '" />' . (JHtml::_('form.token')) .
        '
		</form></td></tr>';
        
          
        $contentx .='</table>';
}


// login

if ($type == 'login')
{

    if ($orient == 2)
    {
        //vertical
        $contentx .= '<span id="starttext">'.$starttext.'</span><br/><form action="' . (JRoute::_('index.php', true, $params->get('usesecure'))) .
            '" method="post" id="login-formx" >';
        if ($params->get('pretext'))
        {
            $contentx .= '
		<div class="pretextx">
		<p>' . ($params->get('pretext')) . '</p>
		</div>';
        }

        // internal labels

        if ($internal == 1)
        {

            $contentx .= '<fieldset class="userdatax">
	<p id="form-login-usernamex" style="margin-bottom:6px;border:0px">
		
		<input id="modlgn-usernamex" type="text" name="username" class="inputbox"   onfocus="if (this.value==\''. $username .'\') this.value=\'\';" onblur="if (this.value==\'\') this.value=\''. $username .'\';" value="'. $username .'"  />
	</p>
	<p id="form-login-passwordx" style="margin-bottom:6px;border:0px">
		
		<input id="modlgn-passwdx" type="password" name="password" class="inputbox"  onfocus="if (this.value==\''.$password.'...\') this.value=\'\';" onblur="if (this.value==\'\') this.value=\''.$password.'...\';" value="'.$password.'..."  />
	</p>';
            if (JPluginHelper::isEnabled('system', 'remember'))
            {
                $contentx .= '<table summary="internal" id="form-login-rememberx" style="position:relative;top:3px;margin-bottom:6px;display:' . $frem . ';">
		<tr><td><label for="modlgn-rememberx">' . $rememberm .'</label></td><td>&nbsp;</td><td>
		<input style="vertical-align:text-bottom;position:relative;top:-1px;" id="modlgn-rememberx" type="checkbox" name="remember" class="inputbox" value="yes"/>
</td></tr>	</table><br/>';
            }

        }
        // external labels

        else
        {

            $contentx .= '<fieldset class="userdatax">
	<p id="form-login-usernamex">
		<label id="label1x" for="modlgn-usernamex">' . $username .
                '</label><br/>
		<input id="modlgn-usernamex" type="text" name="username" class="inputbox"   />
	</p>
	<p id="form-login-passwordx" style="margin-bottom:3px;">
		<label for="modlgn-passwdx">' . $password .
                '</label><br/>
		<input id="modlgn-passwdx" type="password" name="password" class="inputbox"   />
	</p>';
            if (JPluginHelper::isEnabled('system', 'remember'))
            {
                $contentx .= '<table summary="external2" id="form-login-rememberx" style="margin-bottom:6px;display:' . $frem . ';">
		<tr><td><label for="modlgn-rememberx">' . $rememberm . '</label></td><td>&nbsp;</td><td>
		<input style="vertical-align:text-bottom;position:relative;top:-1px;" id="modlgn-rememberx" type="checkbox" name="remember" class="inputbox" value="yes"/>
</td></tr>	</table><br/>';
            }

        }
        //button
        
        $contentx .= '<input style="margin-left:6px;margin-top:10px;" type="' . $btntype .
            '"  name="Submit" onmouseover="this.style.opacity=.7;" onmouseout="this.style.opacity=1;" class="buttonx" value="' . (JText::
            _('JLOGIN')) . '"  src="' . $url .
            'modules/mod_loginplus17v13/tmpl/images/buttons/' . $loginbtn . '_login' . $btnheight .
            '/' . $loginbtncolour . '.png"/>
	<input type="hidden" name="option" value="com_users" />
	<input type="hidden" name="task" value="user.login" />
	<input type="hidden" name="return" value="' . $return . '" />' . (JHtml::_('form.token')) .
            '</fieldset>
	<ul>
		<li style="display:' . $fp . ';">
			<a class="linkx" href="' . (JRoute::_('index.php?option=com_users&view=reset')) . '">' . $forgotp. '</a><br />
		</li>
		<li style="display:' . $fn . ';">
			<a class="linkx" href="' . (JRoute::_('index.php?option=com_users&view=remind')) . '">' . $forgotu. '</a><br />
		</li>';

        $usersConfig = JComponentHelper::getParams('com_users');
        if ($usersConfig->get('allowUserRegistration'))
        {
            $contentx .= '
		<li style="display:' . $fr . ';" >
			<a class="linkx"  href="' . (JRoute::_('index.php?option=com_users&view=registration')) .
                '">' . $createa. '</a><br />
		</li>';
        }
        $contentx .= '</ul>';
        if ($params->get('posttext'))
        {
            $contentx .= '<div class="posttext">
		<p>' . ($params->get('posttext')) . '</p>
		</div>';
        }
        $contentx .= '</form><br /><span id="endtext">'.$endtext.'</span>';
    } else
    {
        



//horizontal

$contentx .= '<span id="starttext">'.$starttext.'</span>';
        if ($params->get('pretext'))
        {
            $contentx .= '
		<div class="pretextx">
		<p>' . ($params->get('pretext')) . '</p>
		</div>';
        }
        
        
        $contentx .= '
<form action="' . (JRoute::_('index.php', true, $params->get('usesecure'))) .
            '" method="post" id="login-formx" ><div id="item_btn"><input style="margin-right:10px;" type="' .
            $btntype . '"  name="Submit" onmouseover="this.style.opacity=.7;" onmouseout="this.style.opacity=1;" class="buttonx" value="' . (JText::_('JLOGIN')) . '"  src="' . $url .'modules/mod_loginplus17v13/tmpl/images/buttons/' . $loginbtn . '_login' . $btnheight .
            '/' . $loginbtncolour . '.png"/></div>
    
        <div class="row">';
        
       
//internal labels 
       
if ($internal == 1){$contentx .= '
<div class="item"><input id="modlgn-usernamex" type="text" onfocus="if (this.value==\''. $username .'\') this.value=\'\';" onblur="if (this.value==\'\') this.value=\''.$username .'\';" value="'. $username .'"  name="username" class="inputboxx"   /></div>
        	<div class="item"><input id="modlgn-passwdx" onfocus="if (this.value==\''.$password.'...\') this.value=\'\';" onblur="if (this.value==\'\') this.value=\''.$password.'...\';" value="'.$password.'..."  type="password" name="password"  class="inputboxx"   /></div>';}
            
//external labels 

if ($internal == 2){$contentx .= '
<div class="item"><label id="modlgn-usernamex"  for="modlgn-usernamex">' . $username .
                '</label>
		<input id="modlgn-usernamex2" type="text" name="username" class="inputbox"   />
		<label id="modlgn-passwdx" for="modlgn-passwdx" class="inputboxx">' . $password. '</label>
		<input id="modlgn-passwdx2" type="password" name="password" class="inputboxx"   /></div>'; }        
            
            
 $contentx .= '<div style="margin-top:2px;" class="item"><label style="display:'.$frem.';font-size:'.$fontpx.'px !important;" for="modlgn-rememberx">' . $rememberm. '</label>';
        	
            
            if (JPluginHelper::isEnabled('system', 'remember')){$contentx .=
            '<div style="display:'.$frem.';margin-left:2px;"><input id ="modlgn-rememberx" style="vertical-align:text-bottom;position:relative;top:-2px;"  type="checkbox" name="remember" class="inputbox" value="yes"/></div>';}

 $contentx .=	'</div></div>
        <div class="row">
        	<div style="display:' . $fp . ';" class="item"><a class="linkx" href="' . (JRoute::_('index.php?option=com_users&view=reset')) . '">' . $forgotp . '</a></div>
        	<div style="display:' . $fn . ';" class="item"><a class="linkx" href="' . (JRoute::_('index.php?option=com_users&view=remind')) . '">' . $forgotu . '</a></div>';
        	
            $usersConfig = JComponentHelper::getParams('com_users');
            if ($usersConfig->get('allowUserRegistration')){$contentx .= '<div style="display:' . $fr . ';" class="item"><a class="linkx" href="' . (JRoute::_('index.php?option=com_users&view=registration')) .
                '">' . $createa . '</a></div>';}
 $contentx .= '</div>
    <input type="hidden" name="option" value="com_users" />
	<input type="hidden" name="task" value="user.login" />
	<input type="hidden" name="return" value="' . $return . '" />' . (JHtml::_('form.token')) .'</form>';           
        
        if ($params->get('posttext'))
        {
            $contentx .= '<div class="posttext">
		<p>' . ($params->get('posttext')) . '</p>
		</div>';
        }
        $contentx .= '<span id="endtext">'.$endtext.'</span>';
    

}}

//*******************************************************Assemble HTML for login panel*************************************************************

echo '<div class="loginplus' . $modno . '" >';

// add graphics if required

if ($graphics == 1)
{
    echo '<div class="holder' . $modno . '">

<table summary="content"  id="contenttable' .
        $modno . '">

<tr>
<td class="corner1_' . $modno . '" >
</td>
<td style="background:url(' . $url . 'modules/' . $surmodulemedia .
        '/tmpl/images/surrounds/' . $surroundstyle . '/' . $keycolour .
        '/top.png) repeat-x">
</td>
<td class="corner2_' . $modno . '" >
</td>

</tr>

<tr>

<td  style="background:url(' . $url . 'modules/' . $surmodulemedia .
        '/tmpl/images/surrounds/' . $surroundstyle . '/' . $keycolour .
        '/sidel.png) repeat-y;">
</td>
<td ><div id="inner' . $modno . '">';
}


//add login/logout form

echo $contentx;

// add remainder of graphics

if ($graphics == 1)
{

    echo '</div>
</td>
<td style="background:url(' . $url . 'modules/' . $surmodulemedia .
        '/tmpl/images/surrounds/' . $surroundstyle . '/' . $keycolour .
        '/sider.png) repeat-y;">
</td>

</tr>

<tr>

<td class="corner3_' . $modno . '" >
</td>
<td style="background:url(' . $url . 'modules/' . $surmodulemedia .
        '/tmpl/images/surrounds/' . $surroundstyle . '/' . $keycolour .
        '/base.png) repeat-x">
</td>
<td class="corner4_' . $modno . '" >
</td>

</tr>
</table>
</div>';
}

echo '</div>';

?>
