<?php
	session_start();
	require('includes/config.php');
		
	$name               = $_REQUEST['category_name'];
	$desc_title_id      = $_REQUEST['category_desc_title_id'];	
	$order              = $_REQUEST['sort_order'];			
	$dtTm               = strtotime(date('d-m-Y'));
	$user               = $_SESSION['userid'];
	$return             = 0;
	$message            = '';	

	$descriptions = explode( "</p>", $_REQUEST['descriptions']);		
	foreach ( $descriptions as $key => $desc ) {
		$desc_text = substr($desc, strpos($desc, '<p>')+3);				
		if( ( $desc_text != '') && ( $desc_text != null ) ){
			$index = $key+1;
			$query = "insert into child_category_parameters( title_id, sort_order, description, created_at, created_by ) values( '".$desc_title_id."', '".$index."', '".$desc_text."', ".$dtTm.", ".$user." )";
			$exe = mysqli_query( $con, $query );
			( $exe ) ? $return = 1 : $return = 0;
		}
	}			
	if( $return ){
		echo json_encode( ['code' => 200,'data' => $message, 'url' => 'descriptions-map' ] );exit;
	}else{
		echo json_encode( ['code' => 405 , 'data' => 'Error Occured' ] );exit;	
	}
?>