<?
class admin
{//DigiHex Systems\\


	function top_shortcuts() {
		global $X;

		$sql=$X->DB->q(' SELECT * FROM _shortcuts WHERE user_id="'.$_SESSION['backend']['user_id'].'" AND row_id IN(7,8) ORDER BY row_id, pozycja, id ');
		while($dane=$X->DB->fa($sql)) {
			$shortcuts[$dane['row_id']].='
				<a href="'.$dane['link'].'" id="shortcut_'.$dane['id'].'">
					<span class="img"><img src="images/icons/large/'.$dane['icon'].'" alt="" '.(!empty($_GET['module']) ? $X->FORM->tip($X->STR->outt($dane['title']),true,-3,12,'tip_small') : '').' /><br />'.($dane['bold']==1 ? '<b>':'').$X->STR->outt($dane['title']).($dane['bold']==1 ? '</b>':'').'</span>
					<span class="ico b_edit action_edit" onclick="shortcut_add(this,'.$dane['id'].')"></span>
					<span class="ico b_no action_del" onclick="shortcut_del(this,'.$dane['id'].')"></span>
					'.$X->FORM->hidden_id('pozycja[]', false, $dane['id']).'
				</a>
			';
		}

		if(!empty($shortcuts)) $X->TOP_SHORTCUTS=true;

		return str_replace(array('/large/','.png'),array('/large_preview/','.jpg'),'
			<form action="/X/" id="top_shortcuts_sort">
				<div class="top_shortcuts" id="top_shortcuts_left"><a class="placeholder" style="display:none"></a>'.$shortcuts[7].'</div>
				<div class="top_shortcuts" id="top_shortcuts_right"><a class="placeholder" style="display:none"></a>'.$shortcuts[8].'</div>
			</form>
		');
	}


	function generate_menu() {
		global $X;

		if(IS_ROOT!=1) {
			$perm_array=$X->DB->get_array(' SELECT module_id FROM _modules2users WHERE user_id="'.$_SESSION['backend']['user_id'].'" ORDER BY module_id ');
			$user_perm=$X->DB->fast(' SELECT is_su, perm_checksum FROM _admin_users WHERE id="'.$_SESSION['backend']['user_id'].'" ');

			$perm_checksum=md5('mod_perm::'.$_SESSION['backend']['user_id'].'>>'.$user_perm['is_su'].'>>'.@serialize($perm_array).'@dh');
			if($perm_checksum!=$user_perm['perm_checksum']) {
				$_SESSION['backend']['xCHECK']['modules']=true;
				if(!empty($_GET['module'])) $X->URL->go('./');
				$cond.=' AND 0 ';
			}
			$cond.=' AND active="1" AND id IN (SELECT module_id FROM _modules2users WHERE user_id="'.$_SESSION['backend']['user_id'].'") ';
		}

		$sql=$X->DB->q(' SELECT id, title, sep FROM _modules WHERE parent_id="0" '.$cond.' ORDER BY pozycja, id ');
		while($dane=$X->DB->fa($sql)) {
			$sel2=$sub=$sel_parent='';
			$sel=($_GET['module']==$dane['id']);

			$sql2=$X->DB->q(' SELECT id, title, sep FROM _modules WHERE parent_id="'.$dane['id'].'" '.$cond.' ORDER BY pozycja, id ');
			while($dane2=$X->DB->fa($sql2)) {
				$sel2=($_GET['module']==$dane2['id']);
				if($sel2==true) {
					$sel_parent=true;
					$X->NAVI[] = $X->STR->outt($dane['title']);
				}
				$sub.='<li><a href="index.php?module='.$dane2['id'].'"'.($sel2==true ? ' class="sel"':'').'>'.$X->STR->outt($dane2['title']).'<i></i></a></li>';
				if($dane2['sep']==1) $sub.='<li class="sep"></li>';
			}
			if(!empty($sub)) {
				$sub_class=' submenu';
				$sub='<ul style="display:'.($sel==true || $sel_parent==true ? 'block':'none').'">'.$sub.'</ul>';
			} else {
				$sub_class=' no-submenu';
			}
			$html.='<li><a href="index.php?module='.$dane['id'].'" class="main'.($sel || $sel_parent==true ? ' sel':'').$sub_class.'">'.$X->STR->outt($dane['title']).'<i></i></a>'.$sub.'</li>';
			if($dane['sep']==1) $html.='<li class="sep"></li>';
		}

		return '
			<ul id="left_menu">
				<li><a href="./" class="main no-submenu'.(empty($_GET['module']) ? ' sel':'').'">Strona główna<i></i></a></li>
				'.$html.'
			</ul>
		';
	}


	function body_color_picker($color) {
		global $X;
		$X->CSS[] = JS.'/jquery.colorpicker/colorpicker.css';
		$X->JS[] = JS.'/jquery.colorpicker/colorpicker.js';

		return '
			'.$X->FORM->hidden('body_color',$color).'
			<div id="body_color_picker" class="color_picker" '.$X->FORM->tip('Zmień kolor panelu',true,-4,5).'><div style="background-color:#'.$color.'"></div></div>
			<script type="text/javascript">
				$(document).ready(function(){
					$("#body_color_picker").ColorPicker({
						onSubmit: function(hsb, hex, rgb, el) {
							$("#body_color").val(hex);
							$("#body_color_picker div").css("backgroundColor", "#"+hex);
							$("#css_color").attr("href","./color-"+hex+".css");
							$.cookie("css_color",hex);
						},
						onBeforeShow: function() {
							if($("#body_color").val().length==6) $(this).ColorPickerSetColor($("#body_color").val());
							$("body, body > *").addClass("nosel");
						},
						onHide: function() {
							$("body, body > *").removeClass("nosel");
						}
					});
				})
			</script>
		';
	}


	function inline_table($table) {
		if(empty($table['body'])) {
			$empty_table=true;
			$table['body']='<tr><td colspan="20" style="background:url(images/pattern1.png); padding:50px 20px 50px 20px; text-align:center; font-size:14px;"><span class="over_pattern_bg"><span class="ico b_error"></span><span>&nbsp;&nbsp;<b>brak pozycji</b></span></span></td></tr>';
		} else {
			$table['body']=str_replace('<tr','<tr'.HOVER, $table['body']);
		}
		return '
			<table class="inline'.(!empty($table['class']) ? ' '.$table['class']:'').'"'.(!empty($table['width']) ? ' width="'.$table['width'].'"':'').'>
				'.($empty_table!=true ? '<thead><tr>'.$table['head'].'</tr></thead>':'').'
				<tbody>'.$table['body'].'</tbody>
				<tfoot>
					<tr>
						<td colspan="20"'.(empty($table['foot']) ? ' class="empty"':'').'>
							<div class="tfoot">'.$table['foot'].'</div>
							<div class="clear"></div>
						</td>
					</tr>
				</tfoot>
			</table>
		';
	}


	function module_name($id=false) {
		global $X;
		if(empty($id)) $id=$_GET['module'];

		return $X->STR->outt($X->DB->fast('SELECT title FROM _modules WHERE id="'.$id.'"'));
	}


	function empty_table($label=false) {
		if(empty($label)) $label='brak pozycji';
		return '<tr><td colspan="20" style="background:#fff url(images/pattern1.png); padding:50px 20px 50px 20px; text-align:center; font-size:14px;"><span class="over_pattern_bg"><span class="ico b_error"></span><span>&nbsp;&nbsp;<b>'.$label.'</b></span></span></td></tr>';
	}


}//DigiHex Systems\\
?>