Accounts.php 6.71 KB
Newer Older
François Jacquet's avatar
François Jacquet committed
1 2
<?php

3
if ($_REQUEST['modfunc']=='update')
François Jacquet's avatar
François Jacquet committed
4
{
5
    if (UserStaffID() && AllowEdit())
François Jacquet's avatar
François Jacquet committed
6
    {
7
        if ($_REQUEST['submit']['delete'])
François Jacquet's avatar
François Jacquet committed
8
        {
François Jacquet's avatar
François Jacquet committed
9
//FJ add translation
10
            if (DeletePromptX(_('User Account')))
François Jacquet's avatar
François Jacquet committed
11 12 13 14 15
                DBQuery('DELETE FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE STAFF_ID='.UserStaffID());
            //unset($_REQUEST['submit']);
        }
        else
        {
16
            if (count($_REQUEST['food_service']))
François Jacquet's avatar
François Jacquet committed
17
            {
18
                if ($_REQUEST['food_service']['BARCODE'])
François Jacquet's avatar
François Jacquet committed
19
                {
20
                    $RET = DBGet(DBQuery("SELECT STAFF_ID FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE BARCODE='".trim($_REQUEST['food_service']['BARCODE'])."' AND STAFF_ID!='".UserStaffID()."'"));
21
                    if ($RET)
François Jacquet's avatar
François Jacquet committed
22 23 24 25 26 27 28
                    {
                        $staff_RET = DBGet(DBQuery("SELECT FIRST_NAME||' '||LAST_NAME AS FULL_NAME FROM STAFF WHERE STAFF_ID='".$RET[1]['STAFF_ID']."'"));
                        $question = _("Are you sure you want to assign that barcode?");
                        $message = sprintf(_("That barcode is already assigned to User <B>%s</B>."),$staff_RET[1]['FULL_NAME']).' '._("Hit OK to reassign it to the current user or Cancel to cancel all changes.");
                    }
                    else
                    {
29
                        $RET = DBGet(DBQuery("SELECT ACCOUNT_ID FROM FOOD_SERVICE_STUDENT_ACCOUNTS WHERE BARCODE='".trim($_REQUEST['food_service']['BARCODE']))."'");
30
                        if ($RET)
François Jacquet's avatar
François Jacquet committed
31 32 33 34 35 36 37
                        {
                            $student_RET = DBGet(DBQuery("SELECT s.FIRST_NAME||' '||s.LAST_NAME AS FULL_NAME FROM STUDENTS s,FOOD_SERVICE_STUDENT_ACCOUNTS fssa WHERE s.STUDENT_ID=fssa.STUDENT_ID AND fssa.ACCOUNT_ID='".$RET[1]['ACCOUNT_ID']."'"));
                            $question = _("Are you sure you want to assign that barcode?");
                            $message = sprintf(_("That barcode is already assigned to Student <B>%s</B>."),$student_RET[1]['FULL_NAME']).' '._("Hit OK to reassign it to the user student or Cancel to cancel all changes.");
                        }
                    }
                }
38
                if (!$RET || PromptX($title='Confirm',$question,$message))
François Jacquet's avatar
François Jacquet committed
39 40 41
                {
                    $sql = 'UPDATE FOOD_SERVICE_STAFF_ACCOUNTS SET ';
                    foreach($_REQUEST['food_service'] as $column_name=>$value)
42
                        $sql .= $column_name."='".trim($value)."',";
François Jacquet's avatar
François Jacquet committed
43
                    $sql = mb_substr($sql,0,-1)." WHERE STAFF_ID='".UserStaffID()."'";
44
                    if ($_REQUEST['food_service']['BARCODE'])
François Jacquet's avatar
François Jacquet committed
45
                    {
46 47
                        DBQuery("UPDATE FOOD_SERVICE_STAFF_ACCOUNTS SET BARCODE=NULL WHERE BARCODE='".trim($_REQUEST['food_service']['BARCODE'])."'");
                        DBQuery("UPDATE FOOD_SERVICE_STUDENT_ACCOUNTS SET BARCODE=NULL WHERE BARCODE='".trim($_REQUEST['food_service']['BARCODE'])."'");
François Jacquet's avatar
François Jacquet committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
                    }
                    DBQuery($sql);
                    unset($_REQUEST['modfunc']);
                    unset($_REQUEST['food_service']);
                    unset($_SESSION['_REQUEST_vars']['food_service']);
                }
            }
        }
    }
    else
    {
        unset($_REQUEST['modfunc']);
        unset($_REQUEST['food_service']);
        unset($_SESSION['_REQUEST_vars']['food_service']);
    }
}

65
if ($_REQUEST['modfunc']=='create')
François Jacquet's avatar
François Jacquet committed
66
{
67
	if (UserStaffID() && AllowEdit())
François Jacquet's avatar
François Jacquet committed
68 69 70
	{
        $fields = 'STAFF_ID,BALANCE,TRANSACTION_ID,';
        $values = "'".UserStaffID()."','0.00','0',";
71 72 73 74 75 76 77 78
        
        if (is_array($_REQUEST['food_service']))
		 foreach($_REQUEST['food_service'] as $column_name=>$value)
		 {
		     $fields .= $column_name.',';
		     $values .= "'".trim($value)."',";
		 }
		 
François Jacquet's avatar
François Jacquet committed
79
        $sql = 'INSERT INTO FOOD_SERVICE_STAFF_ACCOUNTS ('.mb_substr($fields,0,-1).') values ('.mb_substr($values,0,-1).')';
François Jacquet's avatar
François Jacquet committed
80 81 82 83 84 85 86 87 88 89 90
        DBQuery($sql);
	}
	unset($_REQUEST['modfunc']);
}

StaffWidgets('fsa_balance');
StaffWidgets('fsa_status');
StaffWidgets('fsa_barcode');
StaffWidgets('fsa_exists_Y');

$extra['SELECT'] .= ",(SELECT BALANCE FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE STAFF_ID=s.STAFF_ID) AS BALANCE";
91
$extra['SELECT'] .= ",(SELECT coalesce(STATUS,'" . DBEscapeString( _( 'Active' ) ) . "') FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE STAFF_ID=s.STAFF_ID) AS STATUS";
François Jacquet's avatar
François Jacquet committed
92 93 94 95 96
$extra['functions'] += array('BALANCE'=>'red');
$extra['columns_after'] = array('BALANCE'=>_('Balance'),'STATUS'=>_('Status'));

Search('staff_id',$extra);

97
if (UserStaffID() && empty($_REQUEST['modfunc']))
François Jacquet's avatar
François Jacquet committed
98
{
99 100 101 102 103 104 105
	$staff = DBGet(DBQuery("SELECT s.STAFF_ID,s.FIRST_NAME||' '||s.LAST_NAME AS FULL_NAME,
	(SELECT s.STAFF_ID FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE STAFF_ID=s.STAFF_ID) AS ACCOUNT_ID,
	(SELECT STATUS FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE STAFF_ID=s.STAFF_ID) AS STATUS,
	(SELECT BALANCE FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE STAFF_ID=s.STAFF_ID) AS BALANCE,
	(SELECT BARCODE FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE STAFF_ID=s.STAFF_ID) AS BARCODE 
	FROM STAFF s 
	WHERE s.STAFF_ID='".UserStaffID()."'"));
François Jacquet's avatar
François Jacquet committed
106 107
	$staff = $staff[1];

108
	if ($staff['ACCOUNT_ID'])
François Jacquet's avatar
François Jacquet committed
109
	{
110
		echo '<FORM action="Modules.php?modname='.$_REQUEST['modname'].'&modfunc=update" method="POST">';
François Jacquet's avatar
François Jacquet committed
111 112 113 114 115 116 117 118 119 120 121
		DrawHeader('',SubmitButton(_('Save'),'submit[save]').($staff['BALANCE'] == 0 ? SubmitButton(_('Delete Account'),'submit[delete]') : ''));
	}
	else
	{
		echo '<FORM action="Modules.php?modname='.$_REQUEST['modname'].'&modfunc=create" method="POST">';
		DrawHeader('',SubmitButton(_('Create Account')));
	}

	echo '<BR />';
	PopTable('header',_('Account Information'),'width="100%"');

122 123 124
	echo '<TABLE class="width-100p valign-top"><TR>';

	echo '<TD>'.NoInput($staff['FULL_NAME'],$staff['STAFF_ID']);
125 126

	// warn if other users associated with the same account
127
	if (!$staff['ACCOUNT_ID'])
François Jacquet's avatar
François Jacquet committed
128 129
	{
		$warning = _('This user does not have a Meal Account.');
130 131 132

		$tipJS = '<script>var tiptitle1='.json_encode(_('Warning')).'; var tipmsg1='.json_encode($warning).';</script>';

133
		echo '<BR />'.$tipJS.button('warning','','"#" onMouseOver="stm([tiptitle1,tipmsg1])" onMouseOut="htm()" onclick="return false;"');
François Jacquet's avatar
François Jacquet committed
134
	}
135

François Jacquet's avatar
François Jacquet committed
136 137
	echo '</TD>';

138
	echo '<TD>'.NoInput(red($staff['BALANCE']),_('Balance')).'</TD>';
François Jacquet's avatar
François Jacquet committed
139

140 141
	echo '</TR></TABLE>';
	echo '<HR>';
François Jacquet's avatar
François Jacquet committed
142

143
	echo '<TABLE class="width-100p cellspacing-0 valign-top"><TR><TD>';
François Jacquet's avatar
François Jacquet committed
144 145 146 147 148 149 150

	$options = array('Inactive'=>_('Inactive'),'Disabled'=>_('Disabled'),'Closed'=>_('Closed'));
	echo ($staff['ACCOUNT_ID']?SelectInput($staff['STATUS'],'food_service[STATUS]',_('Status'),$options,_('Active')):NoInput('-',_('Status')));
	echo '</TD>';
	echo '<TD>';
	echo ($staff['ACCOUNT_ID']?TextInput($staff['BARCODE'],'food_service[BARCODE]',_('Barcode'),'size=12 maxlength=25'):NoInput('-',_('Barcode')));
	echo '</TD>';
151
	echo '</TR></TABLE>';
François Jacquet's avatar
François Jacquet committed
152 153

	PopTable('footer');
154

155
	echo '<BR /><div class="center">' . SubmitButton( _( 'Save' ) ) . '</div>';
François Jacquet's avatar
François Jacquet committed
156 157
	echo '</FORM>';
}