<?php

        require_once('inc/config.php');
        //require_once('inc/jdf.php');
        if(isset($_GET['hokmId'])){
        $hokmId=$_GET['hokmId'];
        setcookie("hokmId", $hokmId, time() + (86400 * 30), "/");
        }else{
        $hokmId=$_COOKIE['hokmId'];
        }

        $select_user_data="SELECT * FROM `hokm` WHERE hokmId=$hokmId";
        $result_user_data=mysqli_query($db,$select_user_data);
        //echo json_encode($id);
        if(mysqli_num_rows($result_user_data)==1){
        $row_user_data=mysqli_fetch_assoc($result_user_data);
        }else{
        echo "access";
        exit();
        }


// Print two names on the picture, which accepted by query string parameters.

$n1 = $row_user_data['hokm_number'];
$n2 = $row_user_data['hokmdate'];
$n3 = $row_user_data['name'];
$n4 = $row_user_data['semat'];
$n5 = $row_user_data['setad'];
$n6 = $row_user_data['location'];
$n7 = $row_user_data['signer'];
$n8 = $row_user_data['signersemat'];


/*
        require('I18N/Arabic.php'); 
        $Arabic = new I18N_Arabic('Glyphs'); 
        $font = 'ARIAL.TTF';
        $text = $Arabic->utf8Glyphs('آقای فرنام لرستانی');

*/


        $font="/home/irmobash/public_html/network/portal/Btitr.ttf";
        require('Persian/persian_log2vis.php'); 
        persian_log2vis($n3);
        persian_log2vis($n4);
        persian_log2vis($n5);
        persian_log2vis($n6);
        persian_log2vis($n7);
        persian_log2vis($n8);


        Header ("Content-type: image/jpeg");
        $image = imageCreateFromJPEG("jalili-mh.jpg");
        $color = ImageColorAllocate($image, 0, 0, 0);
        $color2 = ImageColorAllocate($image, 0, 57, 133);

        // Calculate horizontal alignment for the names.
        $BoundingBox1 = imagettfbbox(13, 0, $font, $n4);        
        $BoundingBox2 = imagettfbbox(13, 0, $font, $n5);
        $BoundingBox3 = imagettfbbox(13, 0, $font, $n6);
        $BoundingBox4 = imagettfbbox(32, 0, $font, $n7);
        $BoundingBox5 = imagettfbbox(32, 0, $font, $n8);
        
        
        $BoundingBoxname = imagettfbbox(32, 0, $font, $n3); 
        
        $b1 = $BoundingBox1[2]/2; // lower left X coordinate for text
        $b2 = $BoundingBox2[2]/2; // lower left X coordinate for text
        $b3 = $BoundingBox3[2]/2; // lower left X coordinate for text
        $b4 = $BoundingBox4[2]/2;
        $b5 = $BoundingBox5[2]/2;

        // Write names.
        imagettftext($image, 20, 0, 220, 350, $color, $font, $n2);
        imagettftext($image, 20, 0, 220, 430, $color, $font, $n1);
        imagettftext($image, 32, 0, 2100-$BoundingBoxname[2], 950, $color2, $font, $n3);
        imagettftext($image, 32, 0, (1200-$b1), 1360, $color2, $font, $n4);
        imagettftext($image, 32, 0, (1200-$b2), 1460, $color2, $font, $n5);
        //imagettftext($image, 15, 0, (570-$b3), 680, $color2, $font, $n6);
        imagettftext($image, 32, 0, 720-$b4, 2520, $color, $font, $n7);
        //imagettftext($image, 13, 0, 115, 745, $color, 'ARIAL.TTF', $n8);
        imagettftext($image, 32, 0, 720-$b5, 2620, $color, $font, $n8);



        // Return output.
        ImageJPEG($image, NULL, 93);
        ImageJPEG($image, "hokmfile/".$hokmId.".jpg", 93);
        //ImageDestroy($image);
        //ImageDestroy($image);


        //file_put_contents($output, file_get_contents($input));
?>