query( "SELECT * FROM branch WHERE deleted_at IS NULL " . $user_branch_permission_sql_123 ) ; if ( $get_branch->num_rows > 0 ){ while ( $row_branch = $get_branch->fetch_assoc() ){ $branch_all[$row_branch['branch_id']] = $row_branch['branch_name'] ; } } // check permission if ( !permissionCheck($row_user, 'our-category-sub-view') ){ header('Location: index.php') ; exit ; } $mysqli_query_main = "SELECT a.main_id, b.title FROM setting_request a LEFT JOIN setting_request_translation b ON ( a.main_id = b.main_id ) WHERE a.deleted_at IS NULL AND b.lang = 'en' " . $user_branch_permission_sql_symbol ; $mysqli_main = $mysqli->query( $mysqli_query_main ) ; // mode type | all list | new | edit switch($page_mode){ case 'new' : case 'edit' : // check query exsits $submit_type = 'new' ; $mysqli_page = $mysqli->query("SELECT * FROM setting_request_sub WHERE sub_id = '".$page."' LIMIT 1"); if ($mysqli_page->num_rows > 0){ // keep query value in array $row_page = $mysqli_page->fetch_array(MYSQLI_ASSOC) ; $submit_type = 'edit' ; } // update database if ( isset($type) && ( $type == 'new' || $type == 'edit' ) && $_POST['hide'] == 1 ){ if ( $page == '' ){ $mysqli->query( "INSERT INTO setting_request_sub ( created_at ) VALUES ( '".TODAYDATE."' )" ) ; $page = $mysqli->insert_id ; } // resize image // set image in variable $image = $_FILES["image"]["name"] ; $image_query = '' ; $remove_photo = $_POST['remove_photo'] ; if ($remove_photo == 1){ $image = '' ; $image_query = "file = ''," ; } if ( $image != '' ){ $get_image = pathinfo($image) ; $create_image = reCreateImage('Request', 'sub-'.$page, 'sub-'.$page, '', $image, $_FILES["image"]["type"], $_FILES['image']['tmp_name']) ; // Image uploads when exists if ($create_image['result'] && is_array($create_image['crop']) && count($create_image['result']) > 0){ $resizeObj = new resize($create_image['original']) ; // Initialise load image foreach($create_image['crop'] as $value){ // Resize image (options: exact, portrait, landscape, auto, crop) $resizeObj -> resizeImage($value['width'], $value['height'], $value['type']) ; $resizeObj -> saveImage($value['source'], 70) ; // Save image } $get_image = pathinfo($create_image['image']) ; $image_query = "file = '".$create_image['image']."'," ; } } $array_branch = [] ; foreach ( $_POST['branch'] as $k_branch => $v_branch ){ $array_branch[] = escapeString( $v_branch ) ; } // update database $mysqli->query( "UPDATE setting_request_sub SET ".$image_query." branch = '/".implode('/', $array_branch)."/', main_id = '".escapeString($_POST['main_id'])."', type = '".escapeString($_POST['type'])."', title = '".escapeString($_POST['title'])."' WHERE sub_id = '".$page."'" ) ; foreach ( $LANGS as $klang => $vlang ){ $title = escapeString( $_POST['title_'.$klang] ) ; $description = escapeString( $_POST['description_'.$klang] ) ; checkLangUpdate( 'setting_request_sub_translation', 'sub_id', $page, $klang, [ 'title' => [ 'type' => 'input', 'value' => $title ], 'description' => [ 'type' => 'input', 'value' => $description ] ] ) ; } // refresh page header("Location:app-request-sub.php?page_mode=edit&page=".$page."&success=1") ; $_SESSION['system_result'] = 'success-updated' ; exit ; } // start header here include 'requires/page_header.php'; include 'requires/page_top.php'; ?>