<?
class admin
{//DigiHex Systems\\


	function multilang_info($OBJ) {
		global $X;

		if($OBJ->MULTILANG==true) {
			if(count($X->LANGS)>1) {
				foreach($X->LANGS as $L => $T) $lang_opts.='<option value="'.$L.'"'.(LANG==$L ? ' selected="selected"':'').'>'.$T.'</option>';
				$lang='<img src="'.ROOT.'/admin/images/flags/'.strtolower(LANG).'.gif" alt="" style="padding:1px; border:2px solid #fff;" />&nbsp;&nbsp;'.$X->FORM->select('lang',$lang_opts,false,false,'go(\'index.php?module='.$_GET['module'].'&lang=\'+this.value)');
			}
		}
		return $lang;
	}


	function formbox($html, $right=false) {
		global $X;

		return '
			<div class="mainbox_border">
				<div class="mainbox">
					<div class="mainbox_header">
						<div class="mainbox_gear"></div>
						<div class="mainbox_header_navi"><h3>'.@implode(' <span class="sep">&raquo;</span> ',$X->NAVI).'</h3></div>
						'.(!empty($right) ? '<div class="mainbox_header_buttons fright">'.$right.'</div>':'').'
					</div>
					<div class="mainbox_content_form">
						'.$html.'
						<div class="mainbox_content_form_foot">
					</div>
				</div>
			</div>
		';
	}


	function form_actions($edit=false, $skip_back=false, $draft=false, $custom_save=false, $custom_back=false) {
		global $X;
		if(empty($custom_save)) $custom_save='Zapisz';

		return '
			<div class="form_actions">
				'.($skip_back!=true ? $X->FORM->powrot(false,$custom_back,true).'&nbsp;' : '').'
				'.$X->FORM->submit_link($custom_save).'&nbsp;
				'.($draft==true ? '<div class="fright save_as_draft_cont" style="margin-right:-8px">&nbsp;'.$X->FORM->button_OC('<span>Zapisz jako nowy szkic</span>', 'save_as_draft(this); return false;', false, 'button button_gfx').'</div>' : '').'
			</div>
		';
	}


	function file_div($F) {
		global $X;

		if(!empty($F['img_w'])) $w=$F['img_w']+6;
		if(!empty($F['img_h'])) $h=$F['img_h']+50;

		if(!empty($F['cont_w'])) $w=$F['cont_w'];
		if(!empty($F['cont_h'])) $h=$F['cont_h'];

		return '
			<div style="width:'.$w.'px; height:'.$h.'px;">
				'.$X->FORM->hidden($F['name'].'_pozycja['.$F['id'].']',$F['pozycja']).'
				'.$X->FORM->hidden($F['name'].'_exists['.$F['id'].']',$F['file']).'
				'.($F['preview_suff']!==false ? '
					<div class="img" style="height:'.($F['img_h']+4).'px">
						<div style="width:'.($F['img_w']+6).'px">
							<a href="'.$F['dir'].$F['file'].'" target="_blank" class="box_img"><img src="'.$X->FILE->add_suffix($F['dir'].$F['file'],$F['preview_suff']).'" alt="" /></a>
						</div>
					</div>
				':'').'
				'.(isset($F['title']) ? '
					'.$X->FORM->input($F['name'].'_title['.$F['id'].']',(!empty($F['title_w'])? $F['title_w']:275),$F['title'],false,false,'input input_small').'<br />
				':'
					<a class="name" href="'.$F['dir'].$F['file'].'" target="_blank">'.$F['ori_file'].'</a><br />
				').'
				<span class="drag ico b_move"></span>
				<span class="del">'.$X->FORM->checkbox($F['name'].'_del[]',$F['id'],false,false,$F['name'].'_del_'.$F['id']).'<span class="ico b_no" onclick="$(this).prev().click()"></span></span>
				<span class="size">'.$X->FILE->get_size($F['dir'].$F['file']).'</span>
			</div>
		';
	}


	function sort_file_div($name, $data, $use_title=false) {
		global $X;
		if(empty($data)) return false;

		if(substr_count($data,'<div class="img"')>1) $multi=true;
		$X->JS[]=JS.'/jquery.sort/jquery.dragsort.js';
		$sort_js='<script type="text/javascript">$("#'.$name.'_db_data").dragsort({dragSelector:"span.drag"});</script>';

		return '
			<div class="sub_data_cont_cont_check_all"><span>Zaznacz wszystkie &nbsp;</span><span><a href="#" onmouseover="sub_check_all_hover(this)" onclick="sub_check_all(this); return false;" class="sub_check_all" style=""><span class="ico b_no"></span></a></span></div>
			<div id="'.$name.'_db_data" class="sub_data_cont">'.$data.'</div>
			<div class="sub_data_cont_cont_check_all2"><span>Zaznacz wszystkie &nbsp;</span><span><a href="#" onmouseover="sub_check_all_hover(this)" onclick="sub_check_all(this); return false;" class="sub_check_all" style=""><span class="ico b_no"></span></a></span></div>
			'.$sort_js.'
		';
	}


	function file_row($F) {
		global $X;

		return '
			<tr>
				<td>
					'.$X->FORM->hidden($F['name'].'_pozycja['.$F['id'].']',$F['pozycja']).'
					'.$X->FORM->hidden($F['name'].'_exists['.$F['id'].']',$F['file']).'
					<span class="size">'.$X->FILE->get_size($F['dir'].$F['file']).'</span>
					'.(isset($F['title']) ? $X->FORM->input($F['name'].'_title['.$F['id'].']',(!empty($F['title_w'])? $F['title_w']:275),$F['title']).'<div class="clear"></div>' : '').'
					'.$F['custom_html'].'
					<a class="name" href="'.$F['dir'].$F['file'].'" target="_blank">'.$F['ori_file'].'</a>
				</td>
				<td class="del">'.$X->FORM->checkbox($F['name'].'_del[]',$F['id'],false,false,$F['name'].'_del_'.$F['id']).'<span class="ico b_no" onclick="$(this).prev().click()"></span></td>
			</tr>
		';
	}


	function table_file_row($name, $data, $use_title=false, $width=410) {
		global $X;
		if(empty($data)) return false;

		if(substr_count($data,'<tr>')>1) {
			$multi=true;
			$X->JS[]=JS.'/jquery.sort/jquery.tablesort.js';
			$sort_js='<script type="text/javascript">$("#'.$name.'_db_data tbody").tableDnD();</script>';
			$data=str_replace('<tr>','<tr><td class="drag2sort"><i></i></td>',$data);
		}
		$data=str_replace('<tr>','<tr'.HOVER.'>',$data);

		return '
			<table id="'.$name.'_db_data" class="sub_data_cont" style="width:'.$width.'px;">
				<tbody>'.$data.'</tbody>
				'.($multi==true ? '<tfoot><tr><td colspan="10"><a href="#" onmouseover="sub_check_all_hover(this)" onclick="sub_check_all(this); return false;" class="sub_check_all" style=""><span class="ico b_up2"></span></a></td></tr></tfoot>':'').'
			</table>
			'.$sort_js.'
		';
	}


	function table_file_single($name, $dir, $file, $title=false, $width=false, $title_w=false, $preview_suff=false) {
		global $X;
		if(empty($file)) return false;
		if(empty($width)) $width=410;

		return '
			<table id="'.$name.'_db_data" class="sub_data_cont sub_data_cont_single" style="width:'.$width.'px;">
				<tbody>
					<tr>
						<td>
							'.$X->FORM->hidden($name.'_exists[]',$file).'
							'.($preview_suff!==false ? '
								'.($X->FILE->get_ext($dir.$file)=='swf' ? '
									'.$X->FLASH->get('swf_'.time(),$dir.$file,'auto','auto',true).'<br /><br />
								':'
									<a href="'.$dir.$file.'" target="_blank" class="box_img"><img src="'.$X->FILE->add_suffix($dir.$file,$preview_suff).'" alt="" /></a>
								').'
							':'').'
							<span class="size">'.$X->FILE->get_size($dir.$file).'</span>
							'.($title!==false ? $X->FORM->input($name.'_title',(!empty($title_w)? $title_w:295),$title).'<div class="clear"></div>' : '').'
							'.($preview_suff===false ? '<a class="name" href="'.$dir.$file.'" target="_blank">'.$file.'</a>':'').'
							<span class="del">'.$X->FORM->checkbox($name.'_del',1).'<span class="ico b_no" onclick="$(this).prev().click()"></span></span>
						</td>
					</tr>
				</tbody>
			</table>
			'.$sort_js.'
		';
	}


	function save_flash_upload($data) {
		global $X;
		return $X->FILE->save_flash_upload($data);
	}


	function delete_flash_upload($data) {
		global $X;
		return $X->FILE->delete_flash_upload($data);
	}


	function sortable_parse($table, $callback=false) {
		global $X;
		$X->JS[]=JS.'/jquery.sort/jquery.tablesort.js';

		if(empty($table['body'])) $table['body']=$table['empty_body'];

		$row_index=1;
		if(count($table['body'])>0) foreach($table['body'] as $cols) {
			$tbody.='
				<tr'.HOVER.'>
					<td class="drag2sort"><i></i>'.$X->FORM->hidden_id($table['name'].'_row['.$row_index.']','',$row_index).'</td>
					'.str_replace('[]','['.$row_index.']',$cols).'
					'.($table['simple']!=true ? '<td class="sortable_actions"><a href="#" onclick="sortable_del_row(this'.(!empty($callback) ? ','.$callback:'').'); return false;"><span class="ico b_minus"></span></a></td>':'').'
				</tr>
			';
			$row_index++;
		}

		$table['head']=str_replace('</th>','&nbsp;&nbsp;</th>',$table['head']);

		return '
			<table id="'.$table['name'].'_sortable" class="sortable inline'.(!empty($table['class']) ? ' '.$table['class']:'').'"'.(!empty($table['width']) ? ' width="'.$table['width'].'"':'').'>
				'.(!empty($table['head']) ? '<thead><tr><th class="drag2sort"><i></i></th>'.$table['head'].($table['simple']!=true ? '<th><a href="#" onclick="sortable_add_row(this'.(!empty($callback) ? ','.$callback:'').'); return false;"><span class="ico b_plus"></span></a></th>':'').'</tr></thead>':'').'
				<tbody>'.$tbody.'</tbody>
			</table>

			<script type="text/javascript">
				$("#'.$table['name'].'_sortable tbody").tableDnD();
				$("#'.$table['name'].'_sortable").attr("last_row_id",$("#'.$table['name'].'_sortable tbody > tr").length);
			</script>
		';
	}


	function sortable_save($data) {
		global $X;

		$pozycja=1;
		$f=$data['name'];
		$cond='parent_id="'.$data['parent_id'].'" AND param="'.$data['param'].'" ';

		if(count($_POST[$f.'_row'])>0) foreach($_POST[$f.'_row'] as $post_key) {
			$query='';
			$empty_row=true;

			if(count($data['fields'])>0) foreach($data['fields'] as $field) {
				$value = $_POST[$f.'_'.$field][$post_key];
				if($data['dot_conv']==true) $value=str_replace(',','.',$value);

				$query.=$field.'="'.$value.'", ';
				if(!empty($value)) $empty_row=false;
			}

			if($empty_row==false) {
				if($X->DB->fast(' SELECT id FROM '.$data['table'].' WHERE '.$cond.' AND pozycja="'.$pozycja.'" ')==0) {
					$X->DB->q(' INSERT INTO '.$data['table'].' (parent_id,param,pozycja) VALUES ("'.$data['parent_id'].'","'.$data['param'].'","'.$pozycja.'") ');
				}
				$X->DB->q('UPDATE '.$data['table'].' SET '.substr($query,0,-2).' WHERE '.$cond.' AND pozycja="'.$pozycja.'" ');
				$pozycja++;
			}
		}

		$X->DB->q(' DELETE FROM '.$data['table'].' WHERE '.$cond.' AND pozycja>="'.$pozycja.'" ');
	}



}//DigiHex Systems\\
?>