<?php
$must_login            = true ;
$require_path          = '../../../' ;
$require_sub           = '../../' ;
require( $require_sub.'header.php' ) ;

if ( $boolean_login ){
    $status            = '201' ;

    $search_query      = '' ;
    $search_query     .= " AND association_id = '".$array['id']."'" ;

    $query             = "SELECT association_id, association_type, date_start, date_end, file, status, created_at FROM association
                          WHERE deleted_at IS NULL " . $search_query ;
    $mysqli_query      = $mysqli->query( $query ) ;

    if ( $mysqli_query->num_rows > 0 ){
        $status        = '248' ;

        $row           = $mysqli_query->fetch_assoc() ;
        
        $is_association         = 'no' ;
        if ( $row['status'] == 'active' ){
            if ( $row['association_type'] == 'all' || ( $row['association_type'] == 'date' && $row['date_start'] <= TODAYDAY && $row['date_end'] >= TODAYDAY ) ){
                $is_association = 'yes' ;
            }
        }

        if ( $is_association  == 'yes' ){
            $status      = '200' ;

            $mysqli->query( "INSERT INTO staff_association
                             ( association_id, branch_id, staff_id, status ) VALUES
                             ( '".$array['id']."', '".$array['branch_id']."', '".$staff_info['staff_id']."', 'pending' ) " ) ;

            $view_id     = $mysqli->insert_id ;
            $association_so = 'AS'.strPad( 6, $view_id ) ;

            $mysqli->query( "UPDATE staff_association SET association_so = '".$association_so."' WHERE view_id = '".$view_id."'" ) ;

        }
    }
}

require( $require_sub.'footer.php' ) ;
?>