Skip to content
Snippets Groups Projects
cms.class.php 3.52 KiB
Newer Older
Eric Laufer's avatar
Eric Laufer committed
<?php 

class cms{
	private $db;
	private $post = array();
	
	function __construct(){
		global $datenbank;
		$this->db = $datenbank;
	}
	
	public function BoxWahl($id = 0){
		$aus = '';
		foreach($this->db->get_results("SELECT id,name FROM ". PREFIX . B_US ." ") AS $res){
			if($id == $res->id){ $selec = 'selected="selected"';}else{ $selec = '';}
			$aus .= '<option value="'. $res->id .'" '. $selec .'>'. $res->name .'</option>';
		}
		return $aus;
	}
	
	public function LinkZugriff($id){
		$aus  = '
		<option value="1"'; if($id == 1) { $aus .= 'SELECTED';} $aus .= '>Eingeloggte User</option>
		<option value="2"'; if($id == 2) { $aus .= 'SELECTED';} $aus .= '>G&auml;ste</option>
		<option value="3"'; if($id == 3) { $aus .= 'SELECTED';} $aus .= '>Alle</option>
		';
		return $aus;
	}
	
	public function EditSave($post){
		$this->make_array($post);
		$array = array(
			"titel" => $this->post['titel'],
			"text" => $this->post['text'],
			"sichtbar" => $this->post['sichtbar']
		);
		if($this->db->update(PREFIX . CMS, $array, array("id" => $this->post['cms_id'])) == true && $this->LinkUpdate() == true){
			meldung(0,CMS_EDIT_SAVE_TRUE);
		}else{
			meldung(1,CMS_EDIT_SAVE_FALSE);
		}
	}
	
	private function make_array($post){
		foreach($post AS $key => $value){
			if($key != '' && $key != 'seite_save' && $key != 'seite_bearbeiten'){
				$this->post[$key] = $this->db->escape($value);
			}
		}
	}
	
	private function LinkEintragen($id){
		$array = array(
			"link" => 'cms/seite&id='.$id,
			"name" => $this->post['name'],
			"ordnung" => $this->post['ordnung'],
			"box" => $this->post['box'],
			"cms_id" => $id
		);
		$this->db->insert(PREFIX . M_US, $array);
	}
	
	private function LinkUpdate(){
		$array = array(
		"name" => $this->post['name'],
		"ordnung" => $this->post['name'],
		"box" => $this->post['box']
		);
		$return = $this->db->update(PREFIX . M_US, $array, array("cms_id" => $this->post['cms_id']));
		return $return;
	}
	
	public function BoxSave($post){
		$this->make_array($post);
		$array = array(
			"titel" => $this->post['titel'],
			"text" => $this->post['text'],
			"sichtbar" => $this->post['sichtbar']
		);
		if($this->db->insert(PREFIX . CMS, $array) == true){
			$this->LinkEintragen($this->db->lastid());
			meldung(0,CMS_SEITE_SAVE_TRUE);
		}else{
			meldung(1,CMS_SEITE_SAVE_FALSE);
		}
	}
	
	public function ListeSeiten(){
		$aus = '';
		foreach($this->db->get_results("SELECT id,titel,text FROM ". PREFIX . CMS ." ") AS $res){
			$aus .= '
			<form method="post" action="">
				<input type="hidden" name="seiten_id" value="'.$res->id.'">
				<tr>
					<td>'. $res->id .'</td>
					<td>'. $res->titel .'</td>
					<td><code>'. shortText($res->text,200) .'</code></td>
					<td><a class="btn btn-info" href="?page=/cms/detail_seiten&id='. $res->id .'">Bearbeiten</a>&nbsp;
						<input type="submit" class="btn btn-danger" name="run[seite_loeschen]" value="Seite l&ouml;schen"></td>
				</tr>
			</form>
			';
		}
		return $aus;
	}
	
	public function SeiteDelete($post){
		$this->make_array($post);
		if($this->db->num_rows("SELECT id FROM ". PREFIX . CMS ." WHERE id = '". $this->post['seiten_id'] ."' ") == 1){
			if(
				$this->db->delete(PREFIX . CMS, array("id" => $this->post['seiten_id']),1) == true &&
				$this->db->delete(PREFIX . M_US, array("cms_id" => $this->post['seiten_id']),1) == true){
					meldung(0,CMS_DELETE_TRUE);
				}else{
					meldung(1,CMS_DELETE_FALSE);
				}
		}else{
			meldung(1,CMS_SEITE_DELETE_NO);
		}
	}
}