ACC SHELL

Path : /www/hosting/oltv.cz/_/class/system/
File Upload :
Current File : /www/hosting/oltv.cz/_/class/system/admin_uzivatelske_skupiny.php

<?php
/**
* @author Marcel Vykoupil
* @since 18. 09. 2014
*/

class admin_uzivatelske_skupiny extends base {
   const TABLE_NAME = 'admin_uzivatelske_skupiny';

   private $id = null;
   private $caszalozeni = null;
   private $caszmeny = null;
   private $idclanky = null;
   private $nazev = null;
   private $chyba = null;

   public function __construct($id = null) {
      if (!is_null($id) && intval($id) != 0) { // Pokud již položka existuje, zpřístupní její vlastnosti
         $result = dibi::query('SELECT * FROM ['.self::TABLE_NAME.'] WHERE id=%i',intval($id));
         if($result->count() > 0) {
            $row = $result->fetch();
            $this->id = $row->id;
            $this->caszalozeni = $row->caszalozeni;
            $this->caszmeny = $row->caszmeny;
            $this->idclanky = $row->idclanky;
            $this->nazev = $row->nazev;
         } else { notification::infoBox_error("Požadovaná položka nebyla nalezena");redirect("/404.php"); }
      }
   }

   public function getId() { return $this->id; }
   public function getCaszalozeni() { return $this->caszalozeni; }
   public function getCaszmeny() { return $this->caszmeny; }
   public function getIdclanky() { return explode(",",$this->idclanky); }
   public function getNazev() { return $this->nazev; }

   public function setId($id) { $this->id = $id; }
   protected function getChyba() { return $this->chyba; }
   protected function checkData($data) {
      if(array_key_exists("id",$data)) {if(intval($data['id']) > 0) { $this->id = intval($data['id']); } else { $this->chyba .= "ID je v nesprávném formátu<br />"; return false; }}
      return true;
   }

	public function create($variables, $redirectOnEnd = true) {
		$arr = pripravPost($variables);
		$arr["idclanky"] = implode(",", $arr["idclanky"]);
		parent::create($arr, $redirectOnEnd);
	}

	public function edit($variables, $redirectOnEnd = true) {
		$arr = pripravPost($variables);
		$arr["idclanky"] = implode(",", $arr["idclanky"]);
		parent::edit($arr, $redirectOnEnd);
	}

	public function selectableTree($id, $idclanky) {

		$sql = "SELECT nazev, id FROM [clanek] WHERE poradicelkem > 0 AND rodic = %i ORDER BY poradicelkem ASC ";
		$result = dibi::query($sql,$id)->fetchAll();

		if (count($result) > 0) {
			echo "<ul".($id == 0?" id=\"stromovatko\"":"").">\n";
		}

		foreach ($result as $row) {
			echo "<li><input type=\"checkbox\" name=\"idclanky[]\" ".(in_array($row->id, $idclanky)?"checked=\"checked\"":"")." value=\"".$row->id."\"><label>".$row->nazev."</label>";
			self::selectableTree($row->id,$idclanky);
			echo "</li>\n";
		}

		if (count($result) > 0) {
			echo "</ul>\n";
		}
	}

	public static function getPrava($iduser) {
		$prehledClanku = "";
		$clanky_s_povolenim = "";
		$clanky_bez_povoleni = "";
		$sql = "
			SELECT
				A.idclanky, B.typ
			FROM admin_uzivatelske_skupiny A
			LEFT OUTER JOIN [admin_uzivatele_skupiny] B ON A.id = B.idadmin_uzivatelske_skupiny
			WHERE B.idadmin_uzivatele = %i
			ORDER BY B.typ ASC
		";
		$result = dibi::query($sql,intval($iduser));
		foreach($result as $row) {
			foreach(explode(",",$row->idclanky) as $item) {
				if ($row->typ == "admin") { $clanky_s_povolenim .= $row->idclanky.","; }
				if ($row->typ == "user") { $clanky_bez_povoleni .= $row->idclanky.","; }
				$prehledClanku .= clanek::predci($item);
			}
		}

		$prehledClanku = array_unique(explode(",",$prehledClanku));
		$clanky_s_povolenim = array_unique(explode(",",$clanky_s_povolenim));
		$clanky_bez_povoleni = array_unique(explode(",",$clanky_bez_povoleni));
		foreach($prehledClanku as $n => $clanek) {if ($prehledClanku[$n] == "") { unset($prehledClanku[$n]); }}
		foreach($clanky_s_povolenim as $n => $clanek) {if ($clanky_s_povolenim[$n] == "") { unset($clanky_s_povolenim[$n]); }}
		foreach($clanky_bez_povoleni as $n => $clanek) {if ($clanky_bez_povoleni[$n] == "") { unset($clanky_bez_povoleni[$n]); }}

		$user = new admin_uzivatele($iduser);

		$seznamClanku = array(
			"full_control" => ($user->getModul_admin()?1:0),
			"enable_read" => $prehledClanku,
			"enable_write" => $clanky_bez_povoleni,
			"enable_write_create" => $clanky_s_povolenim
		);
		
		return $seznamClanku;
	}

}

ACC SHELL 2018