<?php session_start();
include('accesscheck2.php'); 
require_once('Connections/courier.php');
require_once('functions/functions.php');

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "''";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "''";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "''";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$action=$_POST["act"];
if ($action == "update_permission") {
    $id4 = $_POST['id'];
    mysql_query("DELETE FROM securitypermissions WHERE user_id='$id4'");
    for ($i = 1; $i <= 150; $i++) {
        $item = $_POST['item' . $i];
        if ($item) {
            mysql_query("INSERT INTO securitypermissions (user_id,securitylevel_id) VALUES('$id4', '$item')");
        }
    }
     
    echo 'success@@@Success! The Permission has been updated Successfully.@@@';
    include("admin_utilities/list_users.php");
}

if ($action == "userspermroleedit") {
    $id4 = $_POST['id4'];
    $carrier = strtoupper($_POST['carrier']);
    $query_rsodest = "update security_roles set perm_role='$carrier' where id='$id4';";
    $rsodest = mysql_query($query_rsodest, $courier) or die(mysql_error());
    include("admin_utilities/users_role.php");
}

if ($action == "userrolepermissions") {
    $id4 = $_POST['id4'];
    $query_rsodest = "delete from security_roles_permissions where perm_role_id='$id4'";
    $rsodest = mysql_query($query_rsodest, $courier) or die(mysql_error());
    for ($i = 1; $i <= 150; $i++) {
        $itemtext = 'item' . $i;
        $item = $_POST[$itemtext];
        if ($item) {
            $query_rsodest = "INSERT INTO `security_roles_permissions` (`perm_role_id`, `securitylevel_id`) VALUES ('$id4', '$item');";
            $rsodest = mysql_query($query_rsodest, $courier) or die(mysql_error());
        }
    }
    include("admin_utilities/users_role.php");
}
