<?php
include("user_func.php");
/*
$hddnUserCode = (empty($_SESSION['caller']['args'][1]) || !isset($_SESSION['caller']['args'][1]))?
				$_SESSION['user']['user_code']:$_SESSION['caller']['args'][1];
*/
$hddnUserCode = $_SESSION['caller']['args'][1];		
if ($_SESSION['user']['access_level'] < SABLE_ACCESS_CLERK)
{
	if ((isset($hddnUserCode)) && ($hddnUserCode != $_SESSION['user']['user_code'])) SableSystem::callPage("user/view.php");
}

$usrSQL = "select * 
from user 
where user_code = ".$hddnUserCode;

$row = $sableDB->getRow($usrSQL);

$imgHTML = SableSystem::getClickableImgHTML($row['user_image'], 225, 'imgUser', null);

//Get Addresses
$sql = "select * from user__address 
		inner join client on client.address_id = user__address.address_id
		where user_code = ".$hddnUserCode;
$addresses = $sableDB->getRows($sql);

//Build JS:
	$js  = '<script>'.PHP_EOL;	
	$js .= 'var ddAddress = document.getElementById("selAddress");'.PHP_EOL;
	$js .= 'var tfAddress = document.getElementById("edtAddress");'.PHP_EOL;
	$js .= 'addressItem.setReadOnly(true);'.PHP_EOL;
	foreach($addresses as $address)
	{
		$string = str_replace("\r", "\\r", $address['address']);
		$string = str_replace("\n", "\\n", $string);
		
		$js .= 'tfAddress.value = "'.$string.'";'.PHP_EOL;
		$js .= 'ddAddress.value = "'.$address['address_type_id'].'";'.PHP_EOL;		
		$js .= 'addAddress();'.PHP_EOL;
	}
	
	$js .= '</script>';
?>
<script src="<?php SableGeneralFunctions::printModuleJS('user'); ?>" ></script>
<!--// User -->

<form id="frmUser" name="frmUser" autocomplete="on">
	<input type="hidden" value="<?php echo(SableSystem::sableEncode($hddnUserCode)); ?>" id="hddnUserCode" name="hddnUserCode" />
    <div class="forms_">
        <div class="container">
            <div class="row forms-grids">
                <div class="col-md-12 form-grid">
                    <h3 class="title"><i class="fa fa-eye" aria-hidden="true"></i>&nbsp;View Member</h3>
                    <p></p>
                    <div class="clearfix"></div>
                </div>
            </div>
   
     		<!--// Profile Photo -->
            <div class="row forms-grids"> 
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 forms-grid">
                    <div style="cursor:not-allowed;"><?php echo($imgHTML); ?></div>
                </div>
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                    <input name="edtImage" type="text" id="edtImage" onfocus="showHint('edtImage');" onblur="hideHint('edtImage');" 
                    placeholder="Photo" onkeypress="handleEnter(this, event)" value="<?php echo($row['user_image'])?>" readonly 
                    class="hidden"/>
                    <label class="fieldHint hintUnder" id="hint_edtImage"></label>
                </div>
            </div>        
    
         	<!--// Name & Surname -->
            <div class="row forms-grids"> 
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                    <input name="edtName" type="text" id="edtName" onfocus="showHint('edtName');" onblur="hideHint('edtName');" placeholder="Name" onkeypress="handleEnter(this, event)" value="<?php echo($row['user_name'])?>" readonly />
                    <label class="fieldHint hintUnder" id="hint_edtName">First Name</label>
                </div>                
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                    <input name="edtSurname" type="text" id="edtSurname" onfocus="showHint('edtSurname');" onblur="hideHint('edtSurname');" placeholder="Surname" onkeypress="handleEnter(this, event)" 
                    value="<?php echo($row['user_surname'])?>" readonly/>
                    <label class="fieldHint hintUnder" id="hint_edtSurname">Surname</label>
                </div>
            </div>
        
         	<!--// Email Address & Position -->
            <div class="row forms-grids"> 
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                    <input name="edtEmail" type="text" id="edtEmail" onfocus="showHint('edtEmail');" onblur="hideHint('edtEmail');" placeholder="Email" onkeypress="handleEnter(this, event)" 
                    value="<?php echo($row['user_email'])?>" readonly/>
                    <label class="fieldHint hintUnder" id="hint_edtEmail">Email Address</label>
                </div>
				<div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                    <select name="selPosition" type="select" id="selPosition" class="noArrow"
                    onfocus="showHint('selPosition');" onblur="hideHint('selPosition'); validate_selPosition()"
                    onkeypress="handleEnter(this, event)" placeholder="Position/Role" disabled>
                    <?php echo(SableDBFunctions::getOptions("position", "position_id", "position_title", $row['position_id'])); ?>
                    </select>
                    <label class="fieldHint hintUnder" id="hint_selPosition">Select Position/Role</label>
				</div>
			</div>

         	<!--// Phone Numbers -->
            <div class="row forms-grids">
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                	<label for="edtCell" name="edtCellPrefix" id="edtCellPrefix" class="phonePrefix">
						<?php echo($countryPrefix); ?>
                    </label>
                    <input name="edtCell" type="text" id="edtCell" onfocus="showHint('edtCell');" onblur="hideHint('edtCell');" placeholder="Cell No." onkeypress="handleEnter(this, event)" 
                    value="<?php echo($row['user_cell'])?>" class="phoneInternational" readonly/>
                    <label class="fieldHint hintUnder" id="hint_edtCell">Cell Number</label>
                </div>
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                	<label for="edtPhone" name="edtPhonePrefix" id="edtPhonePrefix" class="phonePrefix">
						<?php echo($countryPrefix); ?>
                    </label>
                    <input name="edtPhone" type="text" id="edtPhone" onfocus="showHint('edtPhone');" onblur="hideHint('edtPhone');" placeholder="Phone No." onkeypress="handleEnter(this, event)" 
                    value="<?php echo($row['user_phone'])?>" class="phoneInternational" readonly />
                    <label class="fieldHint hintUnder" id="hint_edtPhone">Phone Number</label>
                </div>
            </div>
			
         	<!--// Company  -->
            <div class="row forms-grids">
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                    <select name="selCompanyId" type="select" id="selCompanyId" class="noArrow"
                    onfocus="showHint('selCompanyId');" onblur="hideHint('selCompanyId'); validate_selCompanyId()"
                    onkeypress="handleEnter(this, event)" placeholder="Employer" disabled>
                    <?php echo(SableDBFunctions::getOptions("company", "company_id", "company_name", $row['company_id'])); ?>
                    </select>
                    <label class="fieldHint hintUnder" id="hint_selCompanyId">Employer</label>
                </div>
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                </div>
            </div>			
        
        	<!--// Add Addresses -->       
            <div class="row forms-grids" style="display:none;"> 
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                    <select name="selAddress" id="selAddress" onkeypress="handleEnter(this, event)" disabled placeholder="Address Type"  class="noArrow">
                        <?php SableDBFunctions::printOptions('address_type', 'address_type_id', 'address_type_name', -1); ?>
                    </select>
                    <label class="fieldHint hintUnder" id="hint_selAddress">Select address type</label>
                </div>
            </div>
        
            <div class="row forms-grids" style="display:none;"> 
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                    <textarea name="edtAddress" type="text" id="edtAddress" placeholder="Address" 
                    onkeypress="handleEnter(this, event)" rows="6" readonly></textarea>
                    <label class="fieldHint hintUnder" id="hint_edtAddress">Address</label>
                </div>
                <div class="col-xs-4 col-sm-4 col-md-2 col-lg-2 forms-grid">
                </div>                              
            </div>
			
            <div class="row forms-grids">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 forms-grid">
					<div id="addressElement">
						<!--// Selected elements will be placed here. -->
					</div>
					<label class="fieldHint hintUnder" id="hint_edtAddress">Address</label>
				</div>
			</div>
  
        	<!--// buttons -->
			<div class="row forms-grids">
				<div class="col-md-2 forms-grid">
					<input type="button" id="btnCancel" value="Cancel" class="submit" 
						   onclick="window.location = '<?php SableSystem::printCallPageLink('/user/'); ?>'" />
				</div>
				<div class="col-md-2 forms-grid">
					<input id="btnOk" type="button" onclick="editUser('<?php echo(SableSystem::sableEncode($hddnUserCode)); ?>')" value="Modify User" class="submit"/>
				</div>
			</div>
		</div>
        <!-- buttons //--> 
  </div>
</form>
<!-- User //--> 
<?php echo($js); ?>