Output.php 11.4 KB
<?php

/**
 * 	This file is part of ncfilters by netz.coop eG.
 * 
 *  Ncfilters 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.
 * 
 *  Ncfilters 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 Ncfilters.  If not, see <http://www.gnu.org/licenses/>.
 *  
 *  Diese Datei ist Teil von ncfilters by netz.coop eG.
 *  
 *  Ncfilters ist Freie Software: Sie können es unter den Bedingungen
 *  der GNU General Public License, wie von der Free Software Foundation,
 *  Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
 *  veröffentlichten Version, weiterverbreiten und/oder modifizieren.
 *  
 *  Ncfilters wird in der Hoffnung, dass es nützlich sein wird, aber
 *  OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
 *  Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
 *  Siehe die GNU General Public License für weitere Details.
 *  
 *  Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
 *  Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
 * 
 */

/**
 * Output
 * Main html Output for project
 * 
 * @author kontakt@nc
 */
class Output {

	public function printhead() {
		$string = '<!DOCTYPE html>';
		$string .= '<html lang="en">';
		$string .= '<head>';
		$string .= '<!-- Required meta tags -->';
		$string .= '<meta charset="utf-8">';
		$string .= '<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">';
		$string .= '<!-- Bootstrap CSS -->';
		$string .= '<link rel="stylesheet" href="include/libs/bootstrap-4.0.0/css/bootstrap.min.css" >';

		$string .= '<link rel="stylesheet" href="include/css/basic.css" >';
		$string .= '<script src="include/libs/jquery/js/jquery-3.2.1.slim.min.js" ></script>';
		$string .= '<script src="include/libs/tether/js/tether.min.js" ></script>';
		$string .= '<script src="include/libs/bootstrap-4.0.0/js/bootstrap.min.js" ></script>';
		$string .= '<script src="include/js/basic.js" ></script>';

		$string .= '</head>';
		return $string;
	}

	public function printlogo($name) {
		$string = '<div class="header">';
		$string .= ' <a href="https://netz.coop"><img class="logo" src="include/images/logo.png" alt="logo" /></a>';
		$string .= '<h1>' . $name . '</h1>';
		$string .= ' </div>';
		return $string;
	}

	public function printfoter() {
		$string = '<div class="footer">
			<small>ncfilters powered by netz.coop eG</small>
		  </div>';
		return $string;
	}

	public function printcollapsebtn($btnname = 'Erweitert', $id = 'collapseId', $type = 'warning') {
		$string .= '<button class="btn btn-' . $type . '" type="button" data-toggle="collapse" data-target="#' . $id . '" aria-expanded="false" aria-controls="' . $id . '"> ' . $btnname . ' </button>';
		return $string;
	}

	public function printcollapsecontent($input, $btnname = 'Erweitert', $id = 'collapseId', $type = 'warning') {

		$string = '<div class="collapse" id="' . $id . '">';
		$string .= '<div class="card card-block">';
		$string .= $input;
		$string .= '</div>';
		$string .= '</div>';
		return $string;
	}

	public function printstartbody() {

		$string = '<body>';
		$string .= '<div class="container">';
		return $string;
	}

	public function printpagename($name = 'ncfilters') {

		$string = '<h1>' . $name . '</h1>';
		$string .= '';
		return $string;
	}

	public function printformstart($name = 'domain', $value = 'print') {
		$string .= '<form class="form-horizontal" method="POST" role="form" >';
		$string .= '<input type="hidden"  name="' . $name . '" value="' . $value . '">';
		return $string;
	}

	public function printformend() {
		$string .= '</form>';
		return $string;
	}

	public function printbutton($name = 'Submit',$type='primary',$title='submit',$class='') {
		$string .= '<input class="btn btn-'.$type.' '.$class.'" type="submit" value="' . $name . '" title="'.$title.'">';

		return $string;
	}

	public function printmsg($text = 'Submit', $type = 'success') {
		$string .= '<div class="alert alert-' . $type . '" role="alert">' . $text . '</div>';

		return $string;
	}

	public function printendbody() {
		$string .= '</div>';
		$string .= '</body>';
		return $string;
	}

	public function printmintablestart() {
		$string .= '<table class="table">';
		$string .= '<tbody>';
		$string .= '<tr>';
		return $string;
	}

	public function printmintableend() {
		$string .= '</tr>';
		$string .= '</tbody>';
		$string .= '</table>';
		return $string;
	}

	public function printmintablecell($content) {
		$string .= '<th>' . $content . '</th>';
		return $string;
	}
	
	public function printdropdown($array,$name,$fieldlabel='name',$fieldvalue='group_id') {
		$string .= '<select name="'.$name.'">';
			foreach ($array as $key => $value) {
				$string .= ' <option value="'.$value[$fieldvalue].'" label="'.$value[$fieldlabel].'">'.$value[$fieldlabel].' ('.$value[$fieldvalue]	.')</option>';
			}
			$string .= ' </select>';
		return $string;
	}
	
	

	public function printtable($ary_head, $ary_content, $controlls = false, $ary_controll = array(), $user = 0) {

		$string = '<table class="table table-responsive">';
		$string .= '<thead class="thead-inverse">';
		$string .= '<tr>';
		$string .= '<th>#</th>';
		if($ary_controll['table']==='pclist'){
			$db = new Connectdb();
			$arraygroups=$db->getgroupids();
//			echo '<pre>';
//			print_r($arraygroups);
//			echo '</pre>';
			
		}
		foreach ($ary_head as $key => $value) {
			if ($value === 'updated' || $value === 'updatedby' || $value === 'intern') {
				
			} else {
				$string .= '<th>' . $value . '</th>';
			}
		}
		$string .= '</tr>';
		$string .= '</thead>';

		$string .= '<tbody>';

		if (key_exists('fastinput', $ary_controll)) {

			$string .= '<form class="form-horizontal" method="POST" role="form" >';
			$string .= '<input type="hidden"  name="table" value="' . $ary_controll['table'] . '">';
			$string .= '<input type="hidden"  name="action" value="fastinput">';
			$i = 0;
			foreach ($ary_content as $key => $value) {

				if ($i === 0) {

					$string .= '<tr>';
					$string .= '<td>' . $this->printbutton('Eintragen') . '</td>';
					foreach ($value as $skey => $svalue) {
						if ($skey === 'updated') {
							$string .= '<input type="hidden"  name="updated" value="' . date("Y-m-d H:i:s") . '">';
						} elseif ($skey === 'updatedby') {
							$string .= '<input type="hidden"  name="updatedby" value="' . $user . '">';
						} else {
							if($ary_controll['table']==='pclist' && $skey === 'group_id'){
//								$string .= '<td>' . $arraygroups[$svalue]['name'].' ('. $svalue .') </td>';
								$string .='<td>';
								$string .= $this->printdropdown($arraygroups,'group_id',$fieldlabel='name',$fieldvalue='group_id');
								$string	.= '</td>';
								
								
							}elseif ($skey === 'id' && $ary_controll['table'] !== 'groups') {
								$string .= '<td></td>';
							} elseif ($skey === 'childlvl') {
								$string .= '<td><input type="number" name="' . $skey . '" value="1"></td>';
							} elseif ($skey === 'enable' || $skey === 'open') {
								$string .= '<input type="hidden" name="' . $skey . '" value="0" />';
								$string .= '<td><input type="CHECKBOX" name="' . $skey . '"></td>';
							} elseif ($skey === 'intern') {
								$string .= '<input type="hidden" name="' . $skey . '" value="0">';
							} elseif ($skey === 'priority') {
								$string .= '<td><input type="number" name="' . $skey . '" value="0"></td>';
							} else {
								$string .= '<td><input type="text" name="' . $skey . '" placeholder="' . $skey . '"></td>';
							}
						}
					}
					$string .= '</tr>';
				}
				$i++;
			}
			$string .= '</form>';
		}


		$i = 0;
		foreach ($ary_content as $key => $value) {
			$string .= '<tr>';
			if (key_exists('delete', $ary_controll)) {
				$string .= '<td><form class="form-horizontal" method="POST" role="form" >';
				$string .= '<input type="hidden"  name="table" value="' . $ary_controll['table'] . '">';
				$string .= '<input type="hidden"  name="action" value="delete">';
				if($ary_controll['table']==='groups'){
					$string .= '<input type="hidden"  name="group_id" value="' . $value['group_id'] . '">';
				}else{
					$string .= '<input type="hidden"  name="id" value="' . $value['id'] . '">';
				}
				$string .= '' . $this->printbutton('löschen','danger  btn-sm') . '';
				$string .= '</form></td>';
			} else {
				$string .= '<td>' . $i . '</td>';
			}

			foreach ($value as $skey => $svalue) {
				if ($skey === 'updated' || $skey === 'updatedby' || $skey === 'intern') {
					
				}elseif ($skey === 'enable' || $skey === 'open') {
					if($value[$skey] ==='0'){
						$string .= '<td><form class="form-horizontal" method="POST" role="form" >';
						$string .= '<input type="hidden"  name="table" value="' . $ary_controll['table'] . '">';
						$string .= '<input type="hidden"  name="action" value="activate">';
						$string .= '<input type="hidden"  name="field" value="'.$skey.'">';
						if($ary_controll['table']==='groups'){
							$string .= '<input type="hidden"  name="group_id" value="' . $value['group_id'] . '">';
						}else{
							$string .= '<input type="hidden"  name="id" value="' . $value['id'] . '">';
						}
						$string .= '' . $this->printbutton('&#10004','danger  btn-sm','Aktivieren') . '';
						$string .= '</form></td>';
					}else{
						$string .= '<td><form class="form-horizontal" method="POST" role="form" >';
						$string .= '<input type="hidden"  name="table" value="' . $ary_controll['table'] . '">';
						$string .= '<input type="hidden"  name="action" value="deactivate">';
						$string .= '<input type="hidden"  name="field" value="'.$skey.'">';
						if($ary_controll['table']==='groups'){
							$string .= '<input type="hidden"  name="group_id" value="' . $value['group_id'] . '">';
						}else{
							$string .= '<input type="hidden"  name="id" value="' . $value['id'] . '">';
						}
						$string .= '' . $this->printbutton('&#10006;','success  btn-sm','Deaktivieren') . '';
						$string .= '</form></td>';
					}
					
					$string .= '<input type="hidden"  name="updatedby" value="' . $user . '">';
				} else {
					if($ary_controll['table']==='pclist' && $skey === 'group_id'){
						$string .= '<td>' . $arraygroups[$svalue]['name'].' ('. $svalue .') </td>';
					}else{
						$string .= '<td>' . $svalue . '</td>';
					}
					
				}
			}

			$string .= '</tr>';
			$i++;
		}
		$string .= '</tbody>';
		$string .= '</table>';
		return $string;
	}

	
	
	public function printlogin(){
		$string = '
			<div id="loginbox">
				 <div class="wrapper">
					<form class="form-signin" action="./" method="post">
						<fieldset>
							<p>
								<input type="text" id="username" name="username" placeholder="Name" value="" maxlength="20" />
							</p>
							<p>
								<input type="password" id="password" name="password" placeholder="Passwort" value="" maxlength="20" />
							</p>
							<p>
								<input type="hidden" name="form_token" value="<?php echo $form_token; ?>" />';
		$string .= $this->printbutton('&#10149; Login','primary  btn-sm','Login') ;
		$string .='					</p>
						</fieldset>
					</form>
				</div>
			</div>';
		echo $string;
	}
	
}