HEX
Server: Apache
System: Linux v38079.2is.nl 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: democfellows (10015)
PHP: 8.1.34
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/creativefellows.nl/test.creativefellows.nl/ergatis/pages/classes/html.class.php
<?php
/*
	* Class:	html
	* Author:	Koen Barbiers
	* Created:	13-01-2014
	
	* creates html elements
*/
class html
{	
	/*
		* elmnt - creates an html element
		* @param tag(str), inner(str), attr(array)
		* @return string
	*/
	public function elmnt($tag, $inner = '', $attr = array())
	{
		$attr = $this->attr($attr);
		$html = '<'.$tag.$attr.'>'.$inner.'</'.$tag.'>';
		return $html;
	}
	
	/*
		* attr - creates attributes for a html element
		* @param attributes(array)
		* @return string
	*/
	public function attr($attributes)
	{
		$html = '';
		
		foreach($attributes as $name => $val)
			$html .= ' ' . $name . '="' . main::h($val) . '"';
		
		return $html;
	}
	
	/*
		* start - creates the html's start
		* @param void
		* @return string
	*/
	public function start()
	{
		return '<!DOCTYPE html>' .
			   '<html lang="nl">';
	}
	
	/*
		* end - creates the html's end
		* @param void
		* @return string
	*/
	public function end()
	{
		return '</html>';
	}
	
	/*
		* head - creates the html's head section
		* @param title(str), styles(array), scripts(array)
		* @return string
	*/
	public function head($title, $styles, $scripts, $viewport = false)
	{
		$html = '<head>' .
					'<meta charset="utf-8">' .
					'<meta name="robots" content="noindex, nofollow">' .
					'<title>' . $title . '</title>' .
					'<base href="' . CONFIG_URL . '" />' .
					'<link rel="shortcut icon" type="image/png" href="images/favicon.png" />';
					
		if($viewport)
			$html .= '<meta name="viewport" content="width=device-width, maximum-scale=2, user-scalable=1">';
		
		foreach($styles as $style)
			$html .= $this->linkCSS($style);
			
		foreach($scripts as $script)
			$html .= $this->linkJS($script);
		
		$html .= '</head>';
		
		return $html;
	}
	
	/*
		* linkCSS - creates html for css linking
		* @param style(str)
		* @return string
	*/
	public function linkCSS($style)
	{
		return '<link rel="stylesheet" type="text/css" href="'.$style.'" />';
	}
	
	/*
		* linkJS - creates html for js linking
		* @param script(str)
		* @return string
	*/
	public function linkJS($script)
	{
		return '<script type="text/javascript" src="'.$script.'"></script>';
	}
	
	/*
		* accordion - creates an accordion
		* @param void
		* @return string
	*/
	public function accordion($parts)
	{
		return $this->elmnt('ul', $parts, array('class' => 'accordion'));
	}
	
	/*
		* accordionPart - creates a accordion part
		* @param title(str), part(str), active(bool)
		* @return string
	*/
	public function accordionPart($title, $part, $active = false)
	{
		$style = ($active)? 'display:block;' : '';
		$class = ($active)? 'active' : '';
		
		$html = '<li>';
		$html .= '<a href="javascript:;" class="part '.$class.'">'.$title.'</a>';
		$html .= '<div class="part" style="'.$style.'">';
		$html .= $part;
		$html .= '</div>';
		$html .= '</a>';
		$html .= '</li>';
		return $html;
	}
	
	/*
		* dataOverview - creates a data overview
		* @param data(array)
		* @return string
	*/
	public function dataOverview($data)
	{
		$html = '<ul class="data_overview">';
		
		foreach($data as $item)
		{
			if(isset($item['value']) && empty($item['value']))
				continue;
			
			if(empty($item['title']))
				$item['title'] = '&nbsp;';
			
			$instruct = (empty($item['comments']))?
				'' : $this->instruction('Opmerkingen', $item['comments']);
			
			$item['value'] = (!is_array($item['value']))?
				main::h($item['value']) :
				$item['value'][0];
			
			$html .= '<li>';
			$html .= '<legend>'.ucfirst($item['title']).'</legend>';
			$html .= '<div>'.$instruct.$item['value'].'</div>';
			$html .= '</li>';
		}
		$html .= '</ul>';
		$html .= '<div class="clear"></div>';
		return $html;
	}
	
	/*
		* instruction - creates the html for the instruction icon and content
		* @param title(str), content(str), clickable(boolean), class(str)
		* @return string
	*/
	public function instruction($title = 'Opmerkingen', $content = '<p>Geen opmerkingen</p>', $clickable = false, $class='', $display = true)
	{
		$clickable = ($clickable)? ' clickable' : '';
		$display = !$display? ' style="display:none;"' : '';
		$html = '<a href="javascript:;" class="instruct'.$class.'"'.$display.'></a>';
		$html .= '<div class="hide'.$clickable.' instruction" data-title="'.$title.'">'.$content.'</div>';
		return $html;
	}
	
	/*
		* suggestorItems - creates the html for suggestor items
		* @param items(array), valuePrefix(str), extraColumns(array), ucfirst(bool), class(str)
		* @return string
	*/
	public function suggestorItems($items, $valuePrefix = '', $extraColumns = array(), $ucfirst = true, $class = '')
	{
		$html = '';
		
		if(empty($items))
			return $html;
			
		foreach($items as $k => $v)
		{
			$html .= '<tr data-id="'.$valuePrefix.$k.'" class="'.$class.'">';
				$v = (array)$v;
				$v = array_merge($v, $extraColumns);
				foreach($v as $nr => $val)
				{
					$html .= '<td>';
					
					$val = main::h($val);
					
					if($ucfirst)
						$val = ucfirst($val);
					
					$html .= $val . '</td>';
				}
			$html .= '</tr>';
		}
		return $html;
	}
	
	/*
		* taskCenter - creates the html for the task center
		* @param void
		* @return string
	*/
	public function taskCenter()
	{
		$html = '<div id="taskCenter">' .
					'<div class="part">' .
						'<div id="taskCenterPage" class="tasks"></div>' .
					'</div>' .
					'<div class="part bottom">' .
						'<a href="javascript:;" id="toggleTaskCenter" class="" title="Taken">Taken</a>' .
					'</div>' .
				'</div>';
				
		return $html;
	}
	
	/*
		* tinymce - creates a tinymce editor
		* @param id(str), content(str), instruction(array)
		* @return string
	*/
	public function tinymce($id, $content, $instruction)
	{
		$attr = array(
			'class' => 'tinymce',
			'id' => $id
		);
		
		$html = $this->elmnt('textarea', main::h($content), $attr);
		$html .= $this->tinymceInstruction($instruction);
		
		return $html;
	}
	
	/*
		* tinymceInstruction - creates a tinymce editor's instruction
		* @param instruction(array)
		* @return string
	*/
	public function tinymceInstruction($instruction)
	{
		if($instruction['active'] != 1)
			return '';
		
		$click	= ($instruction['clickable'] == 1)? true : false;
		$title  = (empty($click))? 'Checklist' : 'Macro';
		
		return $this->instruction($title, $instruction['content'], $click);
	}
	
	/*
		* pageViewerLink - creates a link that triggers the page viewer
		* @param name(str), path(str), listId(str), width(int), class(str), id(int)
		* @return string
	*/
	public function pageViewerLink($name, $path, $listId, $width = 200, $class = 'new', $id = 0)
	{
		$attr = array(
			'data-path' => $path,
			'data-width' => $width,
			'data-list' => $listId,
			'data-id' => $id,
			'href' => 'javascript:;',
			'class' => 'pageViewer ' . $class
		);
		return $this->elmnt('a', $name, $attr);
	}
	
	/*
		* a - creates a link element
		* @param name(str), link(str), class(str), target(str)
		* @return string
	*/
	public function a($name, $link = 'javascript:;', $class = 'pdf', $target = '_blank')
	{
		$attr = array(
			'href' => $link,
			'class' => $class,
			'name' => $name,
			'target' => $target
		);
		return $this->elmnt('a', $name, $attr);
	}
	
	/*
		* hiddenInputs - creates a set of hidden inputs
		* @param data(array)
		* @return string
	*/
	public function hiddenInputs($data)
	{
		$html = '';
		foreach($data as $name => $value) {
			$html .= '<input type="hidden" name="' . main::h($name) . '" value="' . main::h($value) . '">';
		}
		return $html;
	}
	
	/*
		* shortcutsScript - creates a shortcuts script
		* @param void
		* @return string
	*/
	public function shortcutsScript()
	{
		global $oErgatis;
		
		$html = '<script>';
		$html .= 'var shortcuts = {';
		
		$cuts = $oErgatis->listUserShortcuts($oErgatis->originalUserId);
		$shorts = '';
		
		foreach($cuts as $value => $cut)
		{
			$shorts .= ", '".strtoupper($cut)."' : '".main::h(str_replace(array("\n", "\r"), " ", $value))."'";
		}
		
		$html .= substr($shorts, 2) . '};';
		$html .= '</script>';
		
		return $html;
	}
}
?>