<?php 
/********************************************************************************* 
 *  This file is part of Sentrifugo.
 *  Copyright (C) 2014 Sapplica
 *   
 *  Sentrifugo is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Sentrifugo is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Sentrifugo.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Sentrifugo Support <support@sentrifugo.com>
 ********************************************************************************/
?>

<?php 
$role_id = $this->role_id;        
        if($this->layoutflag !='' && $this->layoutflag == 'layout')
	{ ?>
	<div id="breadcrumdiv">
	<?php   if($this->settingsflag == 1){?>
	    <div class="breadcrumbs">
			<span id="widgetshome" class="firstbreadcrumb" onclick="redirecttohome('widgets')">Home</span>
			<span class="arrows">&rsaquo;</span>
			<span>Settings</span>
			<span class="arrows">&rsaquo;</span>
			<span>Widgets</span>
		</div>
	<?php } else if($this->settingsflag == 2) {?>	
		<div class="breadcrumbs">
			<span id="shortcuthome" class="firstbreadcrumb" onclick="redirecttohome('shortcuts')">Home</span>
			<span class="arrows">&rsaquo;</span>
			<span>Settings</span>
			<span class="arrows">&rsaquo;</span>
			<span>Shortcuts</span>
		</div>
    <?php }?>
	</div>
	<div id="maincontentdiv">
	<?php
	 }
	 ?>

<?php 
if($this->menuidcount > 0){ 
?>
<div id="menutabdiv" style="display:none;">
    <?php for($i=0;$i<sizeof($this->menunamearray);$i++){ ?>
		<div class="setting-div-1" id="<?php echo $this->menunamearray[$i]['id'];?>">
		<label><?php echo $this->menunamearray[$i]['menuName'];?></label> 
		<a href="javascript:void(0);" class="close-1" onclick="removesettingsdiv('<?php echo $this->menunamearray[$i]['id'];?>','widgets')"></a>
		</div>
    <?php } ?>
</div>
<?php }?>

<?php if($this->iconidcount > 0 ){ ?>
<div id="icontabdiv" style="display:none;">
		
    <?php 
    $size = (sizeof($this->iconnamearray) > 16) ? 16:sizeof($this->iconnamearray);
    for($j=0;$j<$size;$j++){ 
            if(isset( $this->iconnamearray[$j]['id']) && !empty( $this->iconnamearray[$j]['id'])){
              $iconnamearrayId =  $this->iconnamearray[$j]['id'];
            }else{
              $iconnamearrayId = '';
            }

            if(isset($this->iconnamearray[$j]['iconPath']) && !empty( $this->iconnamearray[$j]['iconPath'])){
              $iconnamearrayIconPath = $this->iconnamearray[$j]['iconPath'];
            }else{
              $iconnamearrayIconPath = '';
            }
            
            if(isset($this->iconnamearray[$j]['menuName']) && !empty( $this->iconnamearray[$j]['menuName'])){
              $iconnamearrayMenuName =$this->iconnamearray[$j]['menuName'];
            }else{
              $iconnamearrayMenuName = '';
            }
    
    ?>
		<div class='setting-div' id='shortcut_<?php echo $iconnamearrayId;?>'>
		<img width='23' height='23' border='0' src=<?php echo $this->baseUrl('public/media/images/menuIcons/shortcuts/').$iconnamearrayIconPath;?> onerror="this.src='<?php echo $this->baseUrl('public/media/images/sampleimg.png')?>'" />
		<label><?php echo $iconnamearrayMenuName;?></label> 
		<a href='javascript:void(0);' class='close-1' onclick="removesettingsdiv(<?php echo $iconnamearrayId;?>,'icon')"></a>
		</div>
    <?php } ?>
</div>
<?php }?>

<div class="profile-tabs">
 <a href="<?php echo BASE_URL;?>welcome" class="sprite reports-back-btn view-settings-back-btn">Back to Dashboard</a>
<div id="error_message" style="display:none;" ></div>

    <div class="profile-tabs-left">
        <ul>
            <li><a href="<?php echo BASE_URL; ?>dashboard/viewprofile"><div class="profile-icon view-profile"></div><p>View Profile</p></a></li>
                <li class="now">
                <div class="profile-icon view-settings-hover"></div><p>Settings</p>
                <div class="absolute-div"></div></li>
                <li><a href="<?php echo BASE_URL; ?>dashboard/changepassword"><div class="profile-icon view-password"></div><p>Change Password</p></a></li>
                <?php 
                if($role_id == SUPERADMINROLE)
                {
                ?>
                <li><a href="<?php echo BASE_URL; ?>dashboard/emailsettings"><div class="profile-icon view-emailsettings"></div><p>Email Settings</p></a></li>
                <?php 
                }
                ?>
        </ul>
        
    </div>
    <div class="profile-tabs-right-settings">
       <div class="profile-tabs-right-inside">
       	 <div class="settings-div">
         	<div id="widgetsspan" onClick="showwidgets()" class="widgets-div actvier">Widgets</div>
			<div id="shortcutspan" onClick="showshortcuticons()" class="no_loader shortcuts-div">Shortcuts</div>
			<div id="loaderdragimg" style="display:none;"><img src="<?php echo $this->baseUrl("public/media/images/loaderwhite_21X21.gif");?>"/></div>
         </div>
         <div class="drag-text">Drag &amp; Drop the menu items on the left into the box below</div>
         <div id="settingstab" class="settings-block"></div>
         <div id="shortcuticontab" class="settings-block" style="display:none;"></div>
		 <span class="settingserror" id="error-set" style="display:none"></span>
		 <div class="note-1"></div>
           <span class="save-div" style="display:none">
                <input type="submit" class="submit_bg" id="savewidget" value="Save" onClick="savemenuwidgets()"/>
            </span>
			<span class="cancel-div" style="display:none">
                <input type="submit" class="submit_bg" id="cancelwidget" value="Cancel" />
            </span>
        
		 
				  <div id="widgetsgridtab">
					 <?php
							
							if(count($this->widgetmessage)>0)
							{
								echo "<div id='messageData'>".$this->widgetmessage."</div>";
							}

							if(!empty($this->widgets)){
								
								$size = (sizeof($this->widgets) > 10)? 10:sizeof($this->widgets);
								for($w = 0; $w <$size; $w++)
								{
						?>
									<div style="clear: both;width:auto;padding-bottom:20px;">
									<?php 
										echo $this->widgets[$w];
									?>
									</div>  
						<?php
								}
							}
						?>
				   </div> 
				   <div id="shortcutgridtab" style="display:none;">
					 <?php
							
							if(count($this->shortcutmessage)>0)
							{
								echo "<div id='messageData'>".$this->shortcutmessage."</div>";
							}

							if(!empty($this->shortcuts)){
								
								for($x = 0; $x <sizeof($this->shortcuts); $x++)
								{
						?>
									<div style="clear: both;width:auto;padding-bottom:20px;">
									<?php 
										echo $this->shortcuts[$x];
									?>
									</div>  
						<?php
								}
							}
						?>
				   </div> 
       </div>
	   
      	   
    </div>
</div>

<script type='text/javascript'>

$(document).ready(function() { 
$("#settingstab").droppable({
	tolerance: 'touch',
	over: function() {
		  $("#settingstab").css('cursor','move');
		  $("#settingstab").addClass("newtr");
	},
	out: function() {
			$("#settingstab").css('cursor','');
			$("#settingstab").removeClass("newtr");
	},
	drop: function() {
		   
			var itemID = $('#dragid').val();
			makeDroppableAjaxCall(itemID); 
			$("#settingstab").css('cursor','');
			
	}
    });
$("#shortcuticontab").droppable({
	tolerance: 'touch',
	over: function() {
		  $("#shortcuticontab").css('cursor','move');
		  $("#shortcuticontab").addClass("newtr");
	},
	out: function() {
			$("#shortcuticontab").css('cursor','');
			$("#shortcuticontab").removeClass("newtr");
	},
	drop: function() {
		   
			var itemID = $('#dragid').val();
			makeDroppableAjaxCall(itemID); 
			$("#shortcuticontab").css('cursor','');
			
	}
    });

	var total_width = $('.profile-tabs').width();
	//var profile_tabs_right_password_width = total_width*(99/100);	
	var profile_tabs_right_password_width = total_width-2;	
	$('.profile-tabs-left').css("width", "150");
	$('.profile-tabs-right-settings').css("width", (profile_tabs_right_password_width-155));
	
	function checkWidth() {
        var total_width = $('.profile-tabs').width();
		var profile_tabs_right_password_width = total_width-2;		
		$('.profile-tabs-left').css("width", "150");
		$('.profile-tabs-right-settings').css("width", (profile_tabs_right_password_width-155));        
    }
	
	$(window).resize(function() {
		checkWidth();
	});

	var disphtml = '';	
	var icondisphtml = '';

   <?php if($this->menuidcount > 0){ ?>
     var disphtml =$("#menutabdiv").html();
	  if(disphtml != ''){
	     $("#settingstab").html(disphtml);
	     $(".save-div").show();
		 $(".cancel-div").show();
	  }
     <?php for($i=0;$i<sizeof($this->menunamearray);$i++){?>
          menuarray.push(<?php echo $this->menunamearray[$i]['id'];?>);
	 
   <?php }} ?>
   
   <?php if($this->iconidcount > 0){ ?>
     var icondisphtml =$("#icontabdiv").html();
	  if(icondisphtml != ''){
	     $("#shortcuticontab").html(icondisphtml);
		 
	  }
    <?php for($j=0;$j<sizeof($this->iconnamearray);$j++){ if(isset($this->iconnamearray[$j])) {?>
         	iconarray.push(<?php echo $this->iconnamearray[$j]['id'];?>);
	<?php }}} ?>
	
	<?php if($this->settingsflag == 2){ ?>
	      showshortcuticons();
	<?php }else if(($this->settingsflag == 1)){?>
	      showwidgets();     
	<?php }else{?>
	       showwidgets();  
    <?php }?> 
 
  $('#cancelwidget').click(function(){                
		window.location = document.referrer;
    });
});
</script>