<?php

include_once "./classes/classListbox.php";
#include_once('./classes/main/security.class.php');
#db users
$usrSQL = "SELECT username FROM sionapros_users WHERE account_status = 'Active' AND username != 'SADMIN'";
$user = new classListBox($db, "users");
$user->set_query($usrSQL, "username", "username");
$user->set_postback(true);
$chUser = $user->display();
$smarty->assign('user', $chUser);
#their profiles
$profSQL = "SELECT user.profile_id,profiles.profile FROM sionapros_user_profiles AS user INNER JOIN sionapros_profiles AS profiles ON";
$profSQL .= " user.profile_id = profiles.profile_id WHERE user.username = '******'";
$profiles = new classListBox($db, "userprofiles");
$profiles->set_query($profSQL, "profile_id", "profile");
$profiles->set_postback(true);
$userProf = $profiles->display();
$smarty->assign('userProf', $userProf);
if ($profiles->get_selectedItemKey() != '') {
    $smarty->assign('button', 'visible');
    unset($_SESSION['userprofiles']);
}
if (!isset($_POST['submit'])) {
    // new form, we (re)set the session data
    SmartyValidate::connect($smarty, true);
    // register our validators
    SmartyValidate::register_validator('usr', 'users', 'notEmpty');
    SmartyValidate::register_validator('prof', 'userprofiles', 'notEmpty');
    // display form
} else {
<?php

include_once "./classes/classListbox.php";
$profSQL = "SELECT profile,profile_id FROM sionapros_profiles";
$profile = new classListBox($db, "profiles");
$profile->set_query($profSQL, "profile_id", "profile");
#$userMods->set_postback(true);
$profs = $profile->display();
$smarty->assign('profs', $profs);
#check that new name doesnt match an already existing name
function check()
{
    global $_POST, $db;
    $chkSQL = "SELECT * FROM sionapros_profiles WHERE profile = '{$_POST['newname']}'";
    $chkSQL .= " AND profile_id != {$_POST['profiles']}";
    if (count($db->execute($chkSQL)) == 0) {
        return true;
    } else {
        return false;
    }
}
if (empty($_POST)) {
    // new form, we (re)set the session data
    SmartyValidate::connect($smarty, true);
    #register criteria
    SmartyValidate::register_criteria('alreadyExists', 'check');
    // register our validators
    SmartyValidate::register_validator('prof', 'profiles', 'notEmpty');
    SmartyValidate::register_validator('newprof', 'newname', 'notEmpty');
    // display form
} else {
<?php

include_once "./classes/classListbox.php";
include_once './classes/security.class.php';
$usrSQL = "SELECT username FROM sionapros_users WHERE account_status = 'Active' AND username != 'SADMIN'";
$user = new classListBox($db, "dbusers");
$user->set_query($usrSQL, "username", "username");
$user->set_postback(true);
$chUser = $user->display();
$smarty->assign('user', $chUser);
$security = new Security($db);
$profAssigned = $security->userProfiles($user->get_selectedItemKey());
if (count($profAssigned) == 0) {
    $msg = 'none';
}
$smarty->assign('msg', $msg);
$smarty->assign('profiles', $profAssigned);
$content = $smarty->fetch('./security/tm0.security.user_profile.tpl.html');
<?php

include_once "./classes/classListbox.php";
include_once './classes/security.class.php';
$profSQL = "SELECT profile,profile_id FROM sionapros_profiles";
$profile = new classListBox($db, "profiles");
$profile->set_query($profSQL, "profile_id", "profile");
$profile->set_postback(true);
$profiles = $profile->display();
$smarty->assign('profiles', $profiles);
$security = new Security($db);
$objects = $security->objectProfiles($profile->get_selectedItemKey());
if (count($objects) == 0) {
    $msg = 'none';
}
$smarty->assign('msg', $msg);
$smarty->assign('objects', $objects);
$content = $smarty->fetch('./security/tm0.security.objects_profile.tpl.html');
<?php

include_once "./classes/classListbox.php";
$SQL = "SELECT value,id FROM sionapros_categories ORDER BY id";
$con = new classListBox($db, "con");
$con->set_query($SQL, "id", "value");
#$userMods->set_postback(true);
$grps = $con->display();
$smarty->assign('cons', $grps);
if (empty($_POST)) {
    // new form, we (re)set the session data
    SmartyValidate::connect($smarty, true);
    // register our validators
    SmartyValidate::register_validator('grp', 'con', 'notEmpty');
    // display form
    #$content = $smarty->fetch('./main/allergy/tm0.allergy.del_allergy_group.tpl.html');
} else {
    // validate after a POST
    SmartyValidate::connect($smarty);
    if (SmartyValidate::is_valid($_POST)) {
        require_once './classes/cats.class.php';
        #get $_POST info
        $id = $con->get_selectedItemKey();
        $SQL = "SELECT * FROM sionapros_faqs WHERE category = '{$id}'";
        $res = $db->execute($SQL);
        $SQL1 = "SELECT * FROM sionapros_news WHERE category = '{$id}'";
        $res1 = $db->execute($SQL1);
        $SQL2 = "SELECT * FROM sionapros_pubs WHERE category = '{$id}'";
        $res2 = $db->execute($SQL2);
        if (count($res) == 0 || count($res1) == 0 || count($res2) == 0) {
            SmartyValidate::disconnect();
<?php

include_once "./classes/classListbox.php";
#db profiles
$profSQL = "SELECT profile_id,profile FROM sionapros_profiles";
$profiles = new classListBox($db, "dbProfiles");
$profiles->set_query($profSQL, "profile_id", "profile");
$profiles->set_postback(true);
$dbProf = $profiles->display();
$smarty->assign('profiles', $dbProf);
#print_r($_POST);
#db users
$obSQL = "SELECT object FROM sionapros_object_profile WHERE profile_id = '{$profiles->get_selectedItemKey()}'";
$object = new classListBox($db, "objectProf");
$object->set_query($obSQL, "object", "object");
$object->set_postback(true);
$obProf = $object->display();
$smarty->assign('objects', $obProf);
if ($object->get_selectedItemKey() != '') {
    $smarty->assign('button', 'visible');
    unset($_SESSION['objectProf']);
}
if (!isset($_POST['submit'])) {
    // new form, we (re)set the session data
    SmartyValidate::connect($smarty, true);
    // register our validators
    SmartyValidate::register_validator('prof', 'dbProfiles', 'notEmpty');
    SmartyValidate::register_validator('obj', 'objectProf', 'notEmpty');
    // display form
} else {
    // validate after a POST