Beispiel #1
0
function Delete_unit($unit_id, $bd)
{
    $deps = List_Departments('', '', $unit_id, $bd);
    if ($deps) {
        return 0;
    } else {
        $query = "DELETE FROM units WHERE unit_id = {$unit_id}";
        $result = $bd->Query($query);
        return 1;
    }
}
}
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;
    }
    $units = List_Units('', '', $bd);
    $departments = List_Departments('', '', '', $bd);
} else {
    $error[$num_errors++] = "Invalid Session ID";
    include "logout.php";
    exit;
}
$result_xsl = "xsl/" . $default_xsl . "/adm_departments.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("nrpUnits", $units);
$smarty->assign("nrpDepartments", $departments);
$result_xml = $smarty->fetch("xml/adm_departments.xml");
    }
    if (!empty($_POST['submit_conf_yes']) || !empty($_POST['submit_conf_no'])) {
        if (!empty($_POST['submit_conf_yes'])) {
            if (Delete_Department($_POST['dep_id'], $bd) == 1) {
                $alert[$num_alerts++] = 'Department deleted successfully';
            } else {
                $error[$num_errors++] = 'There are users linked to this department, so it cannot be removed';
            }
        } else {
            $alert[$num_alerts++] = 'Department deletion cancelled';
        }
        include "adm_departments.php";
        exit;
    } else {
        if (!empty($_GET['dep_id'])) {
            $departments = List_Departments($_GET['dep_id'], '', '', $bd);
        }
    }
    $result_xsl = "xsl/" . $default_xsl . "/adm_departments_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("nrpUnits", $units);
 $departments[0][0] = '';
 $departments[0][1] = $_POST['name'];
 $departments[0][2] = $_POST['acronym'];
 $departments[0][3] = $_POST['description'];
 $departments[0][4] = $_POST['unit_id'];
 $unit = List_Units($departments[0][4], '', $bd);
 $departments[0][5] = $unit[0][1];
 switch (User_Validate_Simple_Field($departments[0][1], 50)) {
     case 0:
         $error[$num_errors++] = "The Name must be filled";
         break;
     case -2:
         $error[$num_errors++] = "There are invalid characteres at the name";
         break;
     case 1:
         $current = List_Departments('', $departments[0][1], '', $bd);
         if ($current) {
             $error[$num_errors++] = "This department name is already in use";
         }
         break;
 }
 switch (User_Validate_Simple_Field($departments[0][2], 15)) {
     case 0:
         $error[$num_errors++] = "The Acronym must be filled";
         break;
     case -2:
         $error[$num_errors++] = "There are invalid characteres at the acronym";
         break;
 }
 if (empty($error)) {
     Insert_Department($departments[0][1], $departments[0][2], $departments[0][3], $departments[0][4], $bd);