$cats[$cat[0]] = $cat[1];
}
$getReg = $usermeta['user_region'];
$regionChildren = array();
foreach ($regionsListChildren[$getReg] as $children) {
    $regionChildren[$children] = $citiesList[$children];
}
if (isset($_POST['user_parent'])) {
    updateFieldWhere('needy', 'user_parent_ta', getManagerParent($_POST['user_parent']), 'user_id=' . $us);
}
$options['fields']['user_address'] = array('Adresas', 'required' => true);
$options['fields']['user_cat'] = array('Kategorija', 'required' => true, 'inputtype' => 'drop', 'drops' => $cats);
$options['fields']['user_region'] = array('Apskritis', 'inputtype' => 'drop', 'drops' => $regionsList, 'required' => true);
$options['fields']['user_city'] = array('Miestas', 'inputtype' => 'drop', 'drops' => $regionChildren, 'required' => true);
$options['fields']['user_phone'] = array('Telefonas', 'len' => 11, 'required' => true);
if ($usermeta['user_person'] == 0) {
    $options['fields']['user_email'] = array('El. paštas');
} elseif ($usermeta['user_person'] == 1) {
    $options['fields']['user_email'] = array('El. paštas', 'required' => true);
}
$options['fields']['user_desc'] = array('Aprašymas', 'inputtype' => 'textarea');
$options['fields']['user_thumb'] = array($usermeta['user_person'] == 0 ? 'Nuotrauka' : 'Logotipas', 'inputtype' => 'photo');
if (isAdmin() or isGridManager()) {
    $options['fields']['user_parent'] = array('Priskirtas kuratorius', 'inputtype' => 'drop', 'drops' => $kuratoriai);
}
updateUsermeta($options, $us, 'needy', 'user_id');
$getTA = getRow('needy', 'user_id = ' . $us);
if ($getTA['user_parent_ta'] > 0) {
    $getTA = getRow('users', 'user_id = ' . $getTA['user_parent_ta']);
    echo '<br><label>Priskirtas tinklo atstovas</label> ' . $getTA['user_fname'] . ' ' . $getTA['user_lname'] . ' ' . $getTA['user_orgname'];
}
		'left fc-150',
		'left fc-150',
		'left fc-100',
		'left fc-100',
		'left fc-120',
		'left fc-dates',
		'left fc-16',
		'left fc-16',
		'',
		),
		
	);
*/
if (isAdmin()) {
    $parent = '';
} elseif (isManager() or isGridManager()) {
    $parent = 'AND needy.user_parent = ' . CUSER;
    /*elseif(isGridManager()) :
    		$children = array();
    		foreach(listData('users', 'user_acctype = 1 AND user_active = 1 AND user_parent = '.CUSER) as $child) $children[] = 'needy.user_parent = '.$child['user_id'];
    		$parent = 'AND (('.implode(' OR ', $children).') OR needy.user_parent_ta = '.CUSER.')';*/
}
getSort('need_id');
$where = 'SELECT need_id, need_name, cat_name, user_fname, user_lname, user_orgname, need_expires, need_desc, need_regdate, a.deleted AS deleted FROM (SELECT need_id, need_name, cat_name, need_type, need_needy, need_expires, need_desc, need_regdate, needs.deleted AS deleted FROM needs LEFT JOIN cats ON needs.need_cat = cats.cat_id WHERE needs.need_type=' . subpage() . ' AND needs.need_full=0) a LEFT JOIN needy ON a.need_needy = needy.user_id WHERE a.need_type=' . subpage() . ' ' . $parent . ' ORDER BY ' . $getsort . $getorder;
/*
	$sortby = array(0 => 'need_id', 1 => 'need_name', 2 => 'cat_name', 3 => 'user_fname', 4 => 'user_lname', 5 => 'user_orgname', 6 => 'need_regdate');*/
formatTable(listData(false, false, pageNum(), $where), $tablefields, $tablehead, $sortby, true, 'nomargin');
pagination(countData(false, false, $where));
$poreikis = array(1 => 'darbo', 2 => 'daikto');
?>
    ?>
<br><small>JPG, PNG, maks. 5 MB</small></label>
			<input type="file" name="user_thumb" id="user_thumb" />
			<br>
			
			<input type="submit" value="Sukurti" name="newuser" />
		</form>
	<?php 
    return;
}
$us = $_GET['user'];
if (countData('users', "user_id = '{$us}'") == 0) {
    err('Toks vartotojas neegzistuoja', 'red');
    return;
}
if (isGridManager() and countData('users', "user_parent = " . CUSER . " AND user_id = '{$us}'") == 0) {
    err('Neturite teisės keisti šio vartotojo duomenis', 'red');
    return;
}
// Edit
$usermeta = getRow('users', 'user_id = ' . $us);
// Title
echo '<div class="edit_header_group">';
echo '<div class="gravatar">' . (strlen($usermeta['user_thumb']) > 16 ? '<img src="' . $usermeta['user_thumb'] . '" onError="this.style.visibility=\'hidden\'" />' : '') . '</div><div class="gname">';
echo '<div class="name">' . ($usermeta['user_person'] == 0 ? $usermeta['user_fname'] . ' ' . $usermeta['user_lname'] : $usermeta['user_orgname']) . '</div>';
echo 'Paskyros vardas: <b>' . $usermeta['user_name'] . '</b> &middot; Paskyros ID: <b>' . $usermeta['user_id'] . '</b>';
echo '<br>Registravosi <b>' . $usermeta['user_registration_datetime'] . '</b> iš <b>' . $usermeta['user_registration_ip'] . '</b> &middot; ';
echo 'Paskutinį kartą jungėsi <b>' . $usermeta['user_lastlogin'] . '</b> iš <b>' . $usermeta['user_lastlogin_ip'] . '</b>';
echo '</div></div>';
$options = array();
if (isAdmin() and $usermeta['user_acctype'] == 0) {
<?php

if ($login->isUserLoggedIn() == false) {
    return;
}
if (!isGridManager()) {
    return;
}
if (isAction('salinti') and getParam()) {
    if (isManager() and countData('needy', "user_parent = " . CUSER . " AND user_id = '" . getParam() . "'") == 0) {
        err('Neturite teisės keisti šio vartotojo duomenis', 'red');
        return;
    }
    if (isGridManager()) {
        $children = array();
        foreach (listData('users', 'user_acctype = 1 AND user_active = 1 AND user_parent = ' . CUSER) as $child) {
            $children[] = 'user_parent = ' . $child['user_id'];
        }
        $parent = '(' . implode(' OR ', $children) . ')';
        if (countData('needy', "(({$parent}) OR user_parent_ta = " . CUSER . ") AND user_id = '" . getParam() . "'") == 0) {
            err('Neturite teisės keisti šio vartotojo duomenis', 'red');
            return;
        }
    }
    $row = getRow('needy', 'user_id = ' . getParam());
    $act = $row['deleted'];
    $act = !$act;
    if (isset($_POST['reason']) or $act == 0) {
        updateFieldWhere('needy', 'deleted', $act, 'user_id = ' . getParam());
        if (isset($_POST['reason']) and ($_POST['reason'] == 1 or $_POST['reason'] == 2 or $_POST['reason'] == 3)) {
            updateFieldWhere('needy', 'delreason', $_POST['reason'], 'user_id = ' . getParam());
<?php

if ($login->isUserLoggedIn() == false) {
    return;
}
if (!isAdmin() and !isGridManager()) {
    return;
}
if (isAction('deaktyvuoti') and getParam()) {
    if (isGridManager() and countData('users', "user_parent = " . CUSER . " AND user_id = '" . getParam() . "'") == 0) {
        err('Neturite teisės keisti šio vartotojo duomenis', 'red');
        return;
    }
    $row = getRow('users', 'user_id = ' . getParam());
    $act = $row['user_active'];
    $act = !$act;
    updateFieldWhere('users', 'user_active', $act, 'user_id = ' . getParam());
    redirect(0, getCurrentLink());
}
$tablefields = array('user_id', array('converter' => array('user_thumb', 'getThumb')), 'user_name', 'user_fname', 'user_lname', 'user_orgname', 'user_phone', 'user_email', array('converter' => array('user_city', 'getCountry')), 'user_lastlogin', array('converter' => array('user_id', 'getUserEditLink')), array('action' => array('user_id', 'deaktyvuoti', '<i title="Aktyvuoti/deaktyvuoti" class="fa fa-times"></i>', false)), 'null');
$tablehead = array('titles' => array('ID', '', '<span title="Paskyros vardas">P. vardas</span>', 'Vardas', 'Pavardė', 'Organizacija', 'Telefonas', 'El. paštas', 'Savivaldybė', 'Pask. k. prisijungė', '', '', ''), 'columns' => array('right fc-60', 'left fc-30', 'left fc-75', 'left fc-75', 'left fc-100', 'left fc-100', 'left fc-90', 'left', 'left fc-125', 'left fc-dates', 'left fc-16', 'left fc-16', ''));
$parent = isGridManager() ? 'AND user_parent = ' . CUSER : '';
getSort('user_id');
$where = 'SELECT * FROM users WHERE user_acctype=' . subpage() . ' ' . $parent . ' ORDER BY ' . $getsort . $getorder;
$sortby = array(0 => 'user_id', 2 => 'user_name', 3 => 'user_fname', 4 => 'user_lname', 5 => 'user_orgname', 6 => 'user_email', 7 => 'user_phone', 8 => 'user_city', 9 => 'user_lastlogin');
formatTable(listData(false, false, pageNum(), $where), $tablefields, $tablehead, $sortby, true, 'nomargin');
pagination(countData(false, false, $where));
?>

<br><br>
<a href="?p=edituser"><i class="fa fa-asterisk"></i> Sukurti vartotoją</a>
<?php

if ($login->isUserLoggedIn() == false) {
    return;
}
if (!isGridManager()) {
    return;
}
if (!subpage()) {
    return;
}
if (isAction('atkurti') and getParam()) {
    $children = array();
    foreach (listData('users', 'user_acctype = 1 AND user_active = 1 AND user_parent = ' . CUSER) as $child) {
        $children[] = 'needy.user_parent = ' . $child['user_id'];
    }
    $parent = '((' . implode(' OR ', $children) . ') OR needy.user_parent_ta = ' . CUSER . ')';
    if (countData(false, false, "SELECT * FROM needs INNER JOIN needy ON needs.need_needy = needy.user_id WHERE needs.need_id = " . getParam() . " AND " . $parent) == 0) {
        err('Neturite teisės keisti šio poreikio duomenis', 'red');
        return;
    }
    $row = getRow('needs', 'need_id = ' . getParam());
    $act = $row['need_full'];
    $act = !$act;
    updateFieldWhere('needs', 'need_full', $act, 'need_id = ' . getParam());
    redirect(0, getCurrentLink());
}
$tablefields = array('need_id', 'need_name', 'need_full_desc', 'need_regdate', array('converter' => array('need_id', 'getThingEditLink')), array('action' => array('need_id', 'atkurti', '<i title="Patenkintą poreikį padaryti nepatenkintu ir grąžinti į Poreikių lentelę" class="fa fa-undo"></i>', false)), 'null');
$tablehead = array('titles' => array('ID', 'Pavadinimas', 'Aprašymas', 'Modifikuotas', '', '', ''), 'columns' => array('right fc-60', 'left fc-150', 'left fc-300', 'left fc-dates', 'left fc-16', 'left fc-16', ''));
$children = array();
foreach (listData('users', 'user_acctype = 1 AND user_active = 1 AND user_parent = ' . CUSER) as $child) {
<?php

if ($login->isUserLoggedIn() == false) {
    return;
}
if (!isAdmin() and !isManager() and !isGridManager()) {
    return;
}
$tablefields = array('obj_type', 'obj_name', 'obj_desc', array('convArray' => array(array('obj_type', 'obj_id'), 'getSearchLink')), 'null');
$tablehead = array('titles' => array('Tipas', 'Rezultatas', 'Kita informacija', '', ''), 'columns' => array('left fc-150', 'left fc-150', 'left fc-300', 'left fc-16', ''));
$term = isset($_GET['srch']) ? $_GET['srch'] : '';
if ($term == '' or strlen($term) < 3) {
    err('Per trumpa paieškos užklausa');
    return;
}
getSort('obj_id');
$where = "\n\tSELECT user_id AS obj_id, 'Vartotojas' AS obj_type, CONCAT(user_fname, ' ', user_lname, ' ', user_orgname) AS obj_name, CONCAT('Paskyros vardas: ', user_name,', el. paštas: ', user_email, ', telefonas: ', user_phone) AS obj_desc FROM users WHERE user_name LIKE ('%{$term}%') OR user_fname LIKE ('%{$term}%') OR user_lname LIKE ('%{$term}%') OR user_orgname LIKE ('%{$term}%') OR user_phone LIKE ('%{$term}%') OR user_email LIKE ('%{$term}%')\n\tUNION\n\tSELECT user_id AS obj_id, 'Stokojantysis' AS obj_type, CONCAT(user_fname, ' ', user_lname, ' ', user_orgname) AS obj_name, CONCAT('El. paštas: ', user_email, ', telefonas: ', user_phone) AS obj_desc FROM needy WHERE user_fname LIKE ('%{$term}%') OR user_lname LIKE ('%{$term}%') OR user_orgname LIKE ('%{$term}%') OR user_phone LIKE ('%{$term}%') OR user_email LIKE ('%{$term}%')\n\tUNION\n\tSELECT need_id AS obj_id, 'Dovanotojas/geradarys' AS obj_type, CONCAT(user_fname, ' ', user_lname) AS obj_name, CONCAT('El. paštas: ', user_email, ', telefonas: ', user_phone) AS obj_desc FROM needs WHERE user_fname LIKE ('%{$term}%') OR user_lname LIKE ('%{$term}%') OR user_phone LIKE ('%{$term}%') OR user_email LIKE ('%{$term}%')\n\tUNION\n\tSELECT need_id AS obj_id, 'Daiktas/darbas' AS obj_type, need_name AS obj_name, need_desc AS obj_desc FROM needs WHERE need_name LIKE ('%{$term}%')\n\t";
$sortby = false;
formatTable(listData(false, false, pageNum(), $where), $tablefields, $tablehead, $sortby, true, 'nomargin');
pagination(countData(false, false, $where));
function theMenu()
{
    $menu = array();
    if (isCustom()) {
        $menu = array();
        if (haveRight(0)) {
            $menu[] = array('need', 'Poreikiai', '1');
        }
        if (haveRight(1)) {
            $menu[] = array('thing', 'Darbai', '1');
        }
        if (haveRight(2)) {
            $menu[] = array('thingd', 'Geradariai', '1');
        }
        if (haveRight(3)) {
            $menu[] = array('needy', 'Stokojantieji / pagalbos gavėjai');
        }
        if (haveRight(4)) {
            $menu[] = array('stats', 'Statistika');
        }
        if (haveRight(5)) {
            $menu[] = array('atsarg', 'Atsarginė duomenų kopija');
        }
        if (haveRight(7)) {
            $menu[] = array('hefo', 'Antraštės ir poraštės');
        }
        if (haveRight(6)) {
            $menu[] = array('pages', 'Statiniai puslapiai');
        }
        if (haveRight(8)) {
            $menu[] = array('blogpages', 'Naujienos');
        }
    }
    if (isManager()) {
        $menu = array(array('home', 'Pradžia'), array('head' => 'PAGALBADAIKTAIS.LT'), array('need', 'Poreikiai', '2'), array('thing', 'Daiktai', '2'), array('head' => 'PAGALBADARBAIS.LT'), array('need', 'Poreikiai', '1'), array('thing', 'Darbai', '1'), array('head' => 'Bendri duomenys'), array('needy', 'Stokojantieji ir paslaugų gavėjai'), array('colleagues', 'Kolegų kontaktai'));
    }
    if (isGridManager()) {
        $menu = array(array('home', 'Pradžia'), array('head' => 'PAGALBADAIKTAIS.LT'), array('need', 'Poreikiai', '2'), array('thing', 'Daiktai', '2'), array('head' => 'PAGALBADARBAIS.LT'), array('need', 'Poreikiai', '1'), array('thing', 'Darbai', '1'), array('head' => 'Bendri duomenys'), array('needy', 'Stokojantieji ir paslaugų gavėjai'), array('users', 'Kuratoriai', '1'), array('colleagues', 'Kolegų kontaktai'), array('head' => 'MANO KURATORIŲ DUOMENYS'), array('needyman', 'Stokojantieji'), array('needman', 'pagalbadaiktais.lt poreikiai', '2'), array('thingman', 'Daiktai', '2'), array('needman', 'pagalbadarbais.lt poreikiai', '1'), array('thingman', 'Darbai', '1'));
    }
    if (isAdmin()) {
        $menu = array(array('home', 'Pradžia'), array('head' => 'PAGALBADAIKTAIS.LT'), array('need', 'Poreikiai', '2'), array('thing', 'Daiktai', '2'), array('thingd', 'Dovanotojai', '2'), array('head' => 'PAGALBADARBAIS.LT'), array('need', 'Poreikiai', '1'), array('thing', 'Darbai', '1'), array('thingd', 'Geradariai', '1'), array('head' => 'Bendri duomenys'), array('edituser', 'Sukurti / keisti vartotojo paskyrą'), array('users', 'Dovanotojai / geradariai', '0'), array('users', 'Kuratoriai', '1'), array('users', 'Tinklo atstovai', '2'), array('users', 'Administratoriai', '3'), array('needy', 'Stokojantieji / pagalbos gavėjai'), array('rights', 'Vartotojų grupės ir teisės'), array('fields', 'Matomi laukai'), array('allusers', 'Visi vartotojai'), array('stats', 'Statistika'), array('atsarg', 'Atsarginė duomenų kopija'), array('laiskai', 'Laiškų siuntimas'), array('head' => 'SVETAINIŲ TURINYS'), array('hefo', 'Antraštės ir poraštės'), array('pages', 'Statiniai puslapiai'), array('blogpages', 'Naujienos'));
    }
    if (CUSER == 1) {
        $menu = array(array('home', 'Pradžia'), array('head' => 'INFORMACINĖ SISTEMA'), array('need', 'Poreikiai', '1'), array('thing', 'Darbai', '1'), array('thingd', 'Geradariai', '1'), array('edituser', 'Sukurti / keisti vartotojo paskyrą'), array('users', 'Dovanotojai / geradariai', '0'), array('users', 'Kuratoriai', '1'), array('users', 'Tinklo atstovai', '2'), array('users', 'Administratoriai', '3'), array('needy', 'Stokojantieji / pagalbos gavėjai'), array('rights', 'Vartotojų grupės ir teisės'), array('fields', 'Matomi laukai'), array('allusers', 'Visi vartotojai'), array('stats', 'Statistika'), array('atsarg', 'Atsarginė duomenų kopija'), array('laiskai', 'Laiškų siuntimas'), array('head' => 'SVETAINĖS TURINYS'), array('hefo', 'Antraštės ir poraštės'), array('pages', 'Statiniai puslapiai'), array('blogpages', 'Naujienos'));
    }
    foreach ($menu as $menuit) {
        if (isset($menuit['head'])) {
            echo '<li class="menuhead">' . $menuit['head'] . '</li>';
        } else {
            $class = '';
            $allowed = array($menuit[0], 'edit' . $menuit[0], 'edit' . $menuit[0] . 's', 'cat' . $menuit[0], 'cat' . $menuit[0] . '1', 'cat' . $menuit[0] . '2', 'cat' . $menuit[0] . 's');
            $allowed2 = array(rtrim($menuit[0], 's'), 'edit' . rtrim($menuit[0], 's'), 'edit' . $menuit[0]);
            if ((in_array(page(), $allowed) or in_array(page(), $allowed2)) and !isset($menuit[2])) {
                $class = 'class="current"';
            }
            if (in_array(page(), $allowed) and isset($menuit[2]) and ($menuit[2] == subpage() or isset($_GET['type']) and $menuit[2] == $_GET['type'])) {
                $class = 'class="current"';
            }
            echo '<li><a href="?p=' . $menuit[0] . (isset($menuit[2]) ? '&subp=' . $menuit[2] : '') . '"' . $class . '>' . $menuit[1] . '</a></li>';
        }
    }
}
<?php

if ($login->isUserLoggedIn() == false) {
    return;
}
if (!isGridManager() and !isManager()) {
    return;
}
$tablefields = array(array('converter' => array('user_thumb', 'getThumb')), 'user_fname', 'user_lname', 'user_email', 'user_phone', array('converter' => array('user_city', 'getCountry')), 'null');
$tablehead = array('titles' => array('', 'Vardas', 'Pavardė', 'El. paštas', 'Telefonas', 'Savivaldybė', ''), 'columns' => array('left fc-30', 'left fc-75', 'left fc-100', 'left fc-200', 'left fc-100', 'left fc-125', ''));
$subpage = (subpage() == 1 or subpage() == 2) ? "user_acctype =" . subpage() : "(user_acctype = 1 OR user_acctype = 2)";
getSort('user_id');
$where = "SELECT * FROM users WHERE {$subpage} AND user_active = 1 ORDER BY " . $getsort . $getorder;
$sortby = array(1 => 'user_fname', 2 => 'user_lname', 3 => 'user_email', 4 => 'user_phone', 5 => 'user_city');
formatTable(listData(false, false, pageNum(), $where), $tablefields, $tablehead, $sortby, true, 'nomargin');
pagination(countData(false, false, $where));
?>
<br><br>
<form action="" method="GET">
<input type="hidden" name="p" value="colleagues" />
<select name="subp">
	<option value="0"<?php 
if (subpage() != 2 and subpage() != 1) {
    echo 'selected="selected"';
}
?>
>Tinklo atstovai ir kuratoriai</option>
	<option value="2"<?php 
if (subpage() == 2) {
    echo 'selected="selected"';
}