require "./inc/nrp_api.php";
}
if (!isset($num_errors)) {
    $num_errors = 0;
}
if (!isset($num_alerts)) {
    $num_alerts = 0;
}
if (Validate_Session($complete_sess_id, $_SERVER['REMOTE_ADDR'], $bd)) {
    Get_Account_Id($sess_id, $account_id, $bd);
    if ($account_id != 'admin') {
        $error[$num_errors++] = "You are not the administrator";
        include "logout.php";
        exit;
    }
    $permissions = List_Permissions('', '', '', '', '', '', $bd);
} else {
    $error[$num_errors++] = "Invalid Session ID";
    include "logout.php";
    exit;
}
$result_xsl = "xsl/" . $default_xsl . "/adm_permissions.xsl";
$smarty->assign("nrpTransform", $result_xsl);
$smarty->assign("nrpSchErrors", $error);
$smarty->assign("nrpSchAlerts", $alert);
$smarty->assign("nrpMasterSessId", $master_session);
$smarty->assign("nrpSessId", $complete_sess_id);
$smarty->assign("nrpUserId", $account_id);
$smarty->assign("nrpPermissions", $permissions);
$smarty->assign("nrpPeople", $people);
$smarty->assign("nrpCourses", $courses);
        $error[$num_errors++] = "You are not the administrator";
        include "logout.php";
        exit;
    }
    if (!empty($_POST['submit_conf_yes']) || !empty($_POST['submit_conf_no'])) {
        if (!empty($_POST['submit_conf_yes'])) {
            Delete_Permission($_POST['perm_id'], $bd);
            $alert[$num_alerts++] = 'Permission deleted successfully';
        } else {
            $alert[$num_alerts++] = 'Permission deletion cancelled';
        }
        include "adm_permissions.php";
        exit;
    } else {
        if (!empty($_GET['perm_id'])) {
            $permissions = List_Permissions($_GET['perm_id'], '', '', '', '', '', $bd);
        }
    }
    $result_xsl = "xsl/" . $default_xsl . "/adm_permissions_remove.xsl";
} else {
    $error[$num_errors++] = "Invalid Session ID";
    include "logout.php";
    exit;
}
$smarty->assign("nrpTransform", $result_xsl);
$smarty->assign("nrpSchErrors", $error);
$smarty->assign("nrpSchAlerts", $alert);
$smarty->assign("nrpMasterSessId", $master_session);
$smarty->assign("nrpSessId", $complete_sess_id);
$smarty->assign("nrpUserId", $account_id);
$smarty->assign("nrpPermissions", $permissions);
             $category_ok = 0;
             break;
         case 1:
             $category_ok = 1;
             break;
     }
     switch (User_Validate_Simple_Field($permissions[0][7], 16)) {
         case 0:
             $error[$num_errors++] = "A Slave Room must be chosen";
             break;
         case -2:
             $error[$num_errors++] = "There are invalid characteres at the slave id";
             break;
     }
     if ($permissions[0][1] xor $permissions[0][3] xor $permissions[0][5]) {
         $current = List_Permissions('', $permissions[0][1], $permissions[0][3], $permissions[0][5], $permissions[0][7], 'room', $bd);
         if ($current) {
             $error[$num_errors++] = 'This permition already exists';
         }
     } else {
         $error[$num_errors++] = "One (and only one) option of master must be chosen";
     }
     if (empty($error)) {
         Insert_Permission($permissions[0][1], $permissions[0][3], $permissions[0][5], $permissions[0][7], 'room', $bd);
         $alert[$num_alerts++] = "New Permision to Room Inserted Successfully";
         include "adm_permissions.php";
         exit;
     }
 }
 $result_xsl = "xsl/" . $default_xsl . "/adm_permissions_room_new.xsl";
 $categories = List_Categories('', '', $bd);
             $category_ok = 0;
             break;
         case 1:
             $category_ok = 1;
             break;
     }
     switch (User_Validate_Simple_Field($permissions[0][7], 16)) {
         case 0:
             $error[$num_errors++] = "A Slave Course must be chosen";
             break;
         case -2:
             $error[$num_errors++] = "There are invalid characteres at the slave id";
             break;
     }
     if ($permissions[0][1] xor $permissions[0][3] xor $permissions[0][5]) {
         $current = List_Permissions('', $permissions[0][1], $permissions[0][3], $permissions[0][5], $permissions[0][7], 'course', $bd);
         if ($current) {
             $error[$num_errors++] = 'This permition already exists';
         }
     } else {
         $error[$num_errors++] = "One (and only one) option of master must be chosen";
     }
     if (empty($error)) {
         Insert_Permission($permissions[0][1], $permissions[0][3], $permissions[0][5], $permissions[0][7], 'course', $bd);
         $alert[$num_alerts++] = "New Permision to Course Inserted Successfully";
         include "adm_permissions.php";
         exit;
     }
 }
 $result_xsl = "xsl/" . $default_xsl . "/adm_permissions_course_new.xsl";
 $categories = List_Categories('', '', $bd);