<?php
include 'connect/cms-config.php' ;
include 'requires/function.php' ;
include 'requires/session.php' ;

// include the class
include 'requires/class_resize.php' ;

// keep parameter in value
$page 				= escapeString($_GET['page']) ;
$gallery_id 		= escapeString($_GET['gallery_id']) ;

// active menu bar
$active_main_menu 	= 'service' ;
$active_sub_menu 	= 'association' ;
$active_menu 		= 'association-list-list' ;

// check permission
if ( !permissionCheck($row_user, 'association-list-gallery') ){
	header('Location: index.php') ;
	exit ;
}

// check query exsits
$mysqli_page = $mysqli->query("SELECT a.gallery_id, a.category_id, a.title, a.file, a.status, a.created_at, a.updated_at, b.staff_id, b.staff_idno, b.staff_name FROM association_gallery a
					   		   LEFT JOIN staff b ON ( a.staff_id = b.staff_id )
							   WHERE a.gallery_id = '".$gallery_id."' LIMIT 1");
if ($mysqli_page->num_rows > 0){
	// keep query value in array
	$row_page    = $mysqli_page->fetch_array(MYSQLI_ASSOC) ;
}else{
	exit ;
}

// update database
if ( $_POST['hide'] == 1 ){

	// update database
	$mysqli->query( "UPDATE association_gallery SET
					 category_id      = '".escapeString($_POST['category_id'])."'
					 WHERE gallery_id = '".$gallery_id."'" ) ;

	// refresh page
	header("Location:app-association-gallery-view.php?page_mode=edit&gallery_id=".$gallery_id."&success=1") ;
	$_SESSION['system_result'] = 'success-updated' ;
	exit ;
}

// start header here
include 'requires/page_header.php';
include 'requires/page_top.php';
?>

<div class="warper container-fluid">   	
	<div class="page-header"><h1>Association Gallery <small>View</small></h1></div>
	<?php
    if ($_SESSION['system_result'] != ''){
        switch($_SESSION['system_result']){
            case 'success-updated' :
                echo '<div class="result_success">'.$lang['Thank you details has been updated'].'</div>' ;	
            break ;
        }
        unset($_SESSION['system_result']) ;
    }
    ?>
    <div class="panel panel-default">
        <div class="panel-heading"></div>
        <div class="panel-body">
            <form method="post" class="form-horizontal" id="quotationForm" enctype="multipart/form-data" action="app-association-gallery-view.php?page_mode=edit&gallery_id=<?= $gallery_id ?>&type=edit" novalidate="novalidate">

            	<div class="form-group">
                    <div class="col-sm-2 control-label">Staff ID</div>
                    <div class="col-sm-9">
                        <input type="text" name="staff_id" class="form-control ui-search-input" readonly value="<?= dataFilter($row_page['staff_name']).' ( '.dataFilter($row_page['staff_idno']).' )' ?>" placeholder="Staff ID" disabled />
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-2 control-label">Title</div>
                    <div class="col-sm-9">
                        <input type="text" name="title" class="form-control ui-search-input" readonly value="<?= dataFilter($row_page['title']) ?>" placeholder="Title" disabled />
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-2 control-label">Status</div>
                    <div class="col-sm-9">
                        <input type="text" name="status" class="form-control ui-search-input" readonly value="<?= ucwords($row_page['status']) ?>" placeholder="Status" disabled />
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-2 control-label">Category</div>
                    <div class="col-sm-9">
                        <select name="category_id" class="chosen-select2 form-control tab_index ui-dropdown-select ui-search-input select2-basic-single">
                        	<option value="">Select Category</option>
                            <?php
                            $mysqli_category = $mysqli->query("SELECT a.category_id, b.title FROM association_gallery_category a
															   LEFT JOIN association_gallery_category_translation b ON ( a.category_id = b.category_id )
															   WHERE a.deleted_at IS NULL AND b.lang = 'en'") ;
                            if ( $mysqli_category->num_rows > 0 ){
                                while ( $row_category = $mysqli_category->fetch_assoc() ){
                                    echo '<option '.( $row_category['category_id'] == $row_page['category_id'] ? 'selected' : '' ).' value="'.$row_category['category_id'].'">'.dataFilter($row_category['title']).'</option>' ;

                                }
                            }
                            ?>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-2 control-label"></div>
                    <div class="col-sm-9">
                        <button type="submit" class="btn btn-purple" style="float:right"><?= $lang['submit']?></button>
                        <input type="hidden" name="hide" value="1">
                        <input type="hidden" name="page_status" value="<?= $submit_type ?>">
                    </div>
                </div>   
            </form>
        </div>
    </div>
</div>

<?php
include 'requires/page_footer.php' ;