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

3 4
require_once 'ProgramFunctions/TipMessage.fnc.php';

5
if ( $_REQUEST['modfunc']=='update')
François Jacquet's avatar
François Jacquet committed
6
{
7
    if (UserStaffID() && AllowEdit())
François Jacquet's avatar
François Jacquet committed
8
    {
9
        if ( $_REQUEST['submit']['delete'])
François Jacquet's avatar
François Jacquet committed
10
        {
François Jacquet's avatar
François Jacquet committed
11
//FJ add translation
12
            if (DeletePromptX(_('User Account')))
François Jacquet's avatar
François Jacquet committed
13 14 15 16 17
                DBQuery('DELETE FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE STAFF_ID='.UserStaffID());
            //unset($_REQUEST['submit']);
        }
        else
        {
18
            if (count($_REQUEST['food_service']))
François Jacquet's avatar
François Jacquet committed
19
            {
20
                if ( $_REQUEST['food_service']['BARCODE'])
François Jacquet's avatar
François Jacquet committed
21
                {
22
                    $RET = DBGet(DBQuery("SELECT STAFF_ID FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE BARCODE='".trim($_REQUEST['food_service']['BARCODE'])."' AND STAFF_ID!='".UserStaffID()."'"));
23
                    if ( $RET)
François Jacquet's avatar
François Jacquet committed
24 25 26
                    {
                        $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?");
François Jacquet's avatar
François Jacquet committed
27
                        $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.");
François Jacquet's avatar
François Jacquet committed
28 29 30
                    }
                    else
                    {
31
                        $RET = DBGet(DBQuery("SELECT ACCOUNT_ID FROM FOOD_SERVICE_STUDENT_ACCOUNTS WHERE BARCODE='".trim($_REQUEST['food_service']['BARCODE']))."'");
32
                        if ( $RET)
François Jacquet's avatar
François Jacquet committed
33 34 35
                        {
                            $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?");
François Jacquet's avatar
François Jacquet committed
36
                            $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.");
François Jacquet's avatar
François Jacquet committed
37 38 39
                        }
                    }
                }
40
                if ( !$RET || PromptX($title='Confirm',$question,$message))
François Jacquet's avatar
François Jacquet committed
41 42
                {
                    $sql = 'UPDATE FOOD_SERVICE_STAFF_ACCOUNTS SET ';
43
                    foreach ( (array) $_REQUEST['food_service'] as $column_name => $value)
44
                        $sql .= $column_name."='".trim($value)."',";
François Jacquet's avatar
François Jacquet committed
45
                    $sql = mb_substr($sql,0,-1)." WHERE STAFF_ID='".UserStaffID()."'";
46
                    if ( $_REQUEST['food_service']['BARCODE'])
François Jacquet's avatar
François Jacquet committed
47
                    {
48 49
                        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
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
                    }
                    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']);
    }
}

67
if ( $_REQUEST['modfunc']=='create')
François Jacquet's avatar
François Jacquet committed
68
{
69
	if (UserStaffID() && AllowEdit())
François Jacquet's avatar
François Jacquet committed
70 71 72
	{
        $fields = 'STAFF_ID,BALANCE,TRANSACTION_ID,';
        $values = "'".UserStaffID()."','0.00','0',";
73 74
        
        if (is_array($_REQUEST['food_service']))
75
		 foreach ( (array) $_REQUEST['food_service'] as $column_name => $value)
76 77 78 79 80
		 {
		     $fields .= $column_name.',';
		     $values .= "'".trim($value)."',";
		 }
		 
François Jacquet's avatar
François Jacquet committed
81
        $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
82 83 84 85 86 87 88 89 90 91 92
        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";
93
$extra['SELECT'] .= ",(SELECT coalesce(STATUS,'" . DBEscapeString( _( 'Active' ) ) . "') FROM FOOD_SERVICE_STAFF_ACCOUNTS WHERE STAFF_ID=s.STAFF_ID) AS STATUS";
94 95
$extra['functions'] += array('BALANCE' => 'red');
$extra['columns_after'] = array('BALANCE' => _('Balance'),'STATUS' => _('Status'));
François Jacquet's avatar
François Jacquet committed
96 97 98

Search('staff_id',$extra);

99
if (UserStaffID() && empty($_REQUEST['modfunc']))
François Jacquet's avatar
François Jacquet committed
100
{
101 102 103 104 105 106 107
	$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
108 109
	$staff = $staff[1];

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

François Jacquet's avatar
François Jacquet committed
121
	echo '<br />';
François Jacquet's avatar
François Jacquet committed
122 123
	PopTable('header',_('Account Information'),'width="100%"');

124
	echo '<table class="width-100p valign-top fixed-col"><tr><td>';
125

126
	echo NoInput( $staff['FULL_NAME'], $staff['STAFF_ID'] );
127 128

	// warn if other users associated with the same account
129
	if ( !$staff['ACCOUNT_ID'] )
François Jacquet's avatar
François Jacquet committed
130
	{
131 132 133 134 135
		echo '<br />' . MakeTipMessage(
			_( 'This user does not have a Meal Account.' ),
			_( 'Warning' ),
			button( 'warning' )
		);
François Jacquet's avatar
François Jacquet committed
136
	}
137

138
	echo '</td><td>';
François Jacquet's avatar
François Jacquet committed
139

140
	echo NoInput( red( $staff['BALANCE'] ), _( 'Balance' ) );
François Jacquet's avatar
François Jacquet committed
141

142
	echo '</td></tr></table>';
François Jacquet's avatar
François Jacquet committed
143
	echo '<hr />';
François Jacquet's avatar
François Jacquet committed
144

145
	echo '<table class="width-100p valign-top fixed-col"><tr><td>';
François Jacquet's avatar
François Jacquet committed
146

147
	$options = array('Inactive' => _('Inactive'),'Disabled' => _('Disabled'),'Closed' => _('Closed'));
François Jacquet's avatar
François Jacquet committed
148
	echo ($staff['ACCOUNT_ID']?SelectInput($staff['STATUS'],'food_service[STATUS]',_('Status'),$options,_('Active')):NoInput('-',_('Status')));
François Jacquet's avatar
François Jacquet committed
149 150
	echo '</td>';
	echo '<td>';
François Jacquet's avatar
François Jacquet committed
151
	echo ($staff['ACCOUNT_ID']?TextInput($staff['BARCODE'],'food_service[BARCODE]',_('Barcode'),'size=12 maxlength=25'):NoInput('-',_('Barcode')));
François Jacquet's avatar
François Jacquet committed
152 153
	echo '</td>';
	echo '</tr></table>';
François Jacquet's avatar
François Jacquet committed
154 155

	PopTable('footer');
156

François Jacquet's avatar
François Jacquet committed
157 158
	echo '<br /><div class="center">' . SubmitButton( _( 'Save' ) ) . '</div>';
	echo '</form>';
François Jacquet's avatar
François Jacquet committed
159
}