ACC SHELL

Path : /srv/www/vhosts/centrumlb/administrace/libs/
File Upload :
Current File : /srv/www/vhosts/centrumlb/administrace/libs/usergroup.class.php

<?php

interface iUsergroup {

    public function fetchSingle($id = false);

    public function fetchAll($arr);

    public function insert($arr);

    public function update($arr);

    public function createOptionBox($id = false);
}

class Usergroup implements iUsergroup {

    public $name = false;
    public $currentpage = 0;
    public $totalpages = 0;
    public $pagesize = 20;
    public $dontDelete = array(1);

    function __construct() {
	
    }

    /**
     *
     * @param int $id single id of users_group
     * @return array
     */
    public function fetchSingle($id = false) {
	if (!$id) {
	    return false;
	}
	$row = dibi::select('*')->from('users_group')->where('id=%i', $id)->fetch();
	if (!$row) {
	    return false;
	}
	return $row;
    }

    public function fetchAll($arr = false) {
	$row = dibi::query('SELECT * FROM users_group')->fetchAll();
	if (!$row) {
	    return false;
	}
	return $row;
    }

    /*
      public function delete($id = false) {
      if (!$id) {
      return false;
      }
      $row = dibi::delete('users_group')->where('id=%i', $id)->execute();
      if (!$row) {
      return false;
      }
      return $row;
      }
     *
     */

    public function insert($arr) {

	$result = dibi::query('INSERT INTO `users_group` ', $arr);

	if ($result) {
	    Tools::message($_MSG['SAVED_OK']);
	    return dibi::insertId();
	} else {
	    Tools::message($_MSG['SAVED_NOK']);
	    return false;
	}
    }

    public function update($arr) {

	$result = dibi::query('UPDATE `users_group` SET ', $arr, 'WHERE `id`=%i', $arr['id']);
	if ($result) {
	    Tools::message($_MSG['SAVED_OK']);
	    return true;
	} else {
	    Tools::message($_MSG['SAVED_NOK']);
	    return false;
	}
    }

    public function getAdminTable() {
	if (isset($_SESSION['listuj']))
	    $this->pagesize = $_SESSION['listuj'];

	if (isset($_GET['recordstart'])) {
	    $recordstart = (isset($_GET['recordstart'])) ? (int) $_GET['recordstart'] : 0;
	}
	else
	    $recordstart = 0;

	$query = "SELECT * FROM users_group ORDER BY id ASC";

	$num_rows = dibi::query($query)->count();

	if ($num_rows > $this->pagesize) {
	    $query .= " LIMIT $recordstart, $this->pagesize";
	}

	$rows = dibi::query($query)->fetchAll();
//NDebugger::dump($rows);
	$this->totalpages = ceil($num_rows / $this->pagesize);
	$this->currentpage = ($recordstart / $this->pagesize) + 1;


	if ($num_rows == 0) {
	    echo '<tr>';
	    echo "<td colspan='5'>Nejsou evidovaní žádní uživatelé.</td>";
	    echo '</tr>';
	} else {
	    foreach ($rows as $row) {
		echo '<tr>';
		echo '<td><input type="checkbox" name="checkbox[]" value="' . $row->id . '" id="" ></td>';
		echo '<td><a href="usergroup_edit.php?id=' . $row->id . '" title="Editovat">' . $row->name . '</td>';
		echo '<td>' . datum_i_cas($row->tm_changed) . '</td>';
		echo '<td><a href="usergroup_edit.php?id=' . $row->id . '" title="Editovat"><img src="images/iko/note_edit.png" alt="Editovat" /></a>';

		if (!in_array($row->id, $this->dontDelete)) {
		    echo '<a href="?smazat=' . $row->id . '" class="potvrzujiciLink" title="Smazat"><img src="images/iko/remove.png" alt="Smazat" /></a></td>';
		}
		echo '</tr>';
	    }
	}
    }

    /**
     * CreateOptionBox
     * 
     * Vytvori option box s uzivatelskymi skupinami. 
     * 
     * @param type $id id skupiny ktere ma byt oznaceno selected
     * @return html option element
     */
    public function createOptionBox($id = false) {
	$string = '';
	$optionBox = dibi::select('id, name')->from('users_group')->fetchAll();
	//NDebugger::dump($optionBox);exit;
	//NDebugger::dump($tata);exit;
	foreach ($optionBox as $n => $row) {
	    $selected = false;
	    $selected = $row->id == $id ? "SELECTED" : "";
	    $string .= sprintf("<option name=\"%d\" id=\"%d\" value=\"%d\" %s>%s</option>\n", $row->id, $row->id, $row->id, $selected, str_repeat("&nbsp;", 3) . $row->name);
	}
	return $string;
    }

    /**
     * createOptionBoxForNewsletter
     * 
     * Vytvori option box s uzivatelskymi skupinami. 
     * @return html option element
     */
    public function createOptionBoxForNewsletter($id = false) {
	$string = '';
	$tata = 0;
	$tata = dibi::query('SELECT id_skupiny FROM newsletter_prirazeni WHERE id_newsletteru =%i', intval($id))->fetchAssoc('id_skupiny');

	$optionBox = dibi::select('id, name')->from('users_group')->fetchAll();
	//NDebugger::dump($optionBox);exit;
	//NDebugger::dump($tata);exit;
	foreach ($optionBox as $n => $row) {
	    $selected = false;
	    $selected = array_key_exists($row->id, $tata) ? "SELECTED" : "";
	    $string .= sprintf("<option name=\"%d\" id=\"%d\" value=\"%d\" %s>%s</option>\n", $row->id, $row->id, $row->id, $selected, str_repeat("&nbsp;", 3) . $row->name);
	}
	return $string;
    }

}

?>

ACC SHELL 2018