<?php

function getPrintTemplate($conn_rjllearning)
{

    $sql = "SELECT * FROM  id_cards_template  where status =? " ;
    $array_params = [1];
    $stmt = $conn_rjllearning->prepare($sql);
    $stmt->execute($array_params);
    $result = $stmt->fetchAll();
    $array_return = [];
 
    if(count($result) >= 1){
       
    foreach ($result as $rows) {
        
        $path = 'https://rejoicebilldesk.in/rjllearning_development/resources/template/students/id_cards/';
        $templatepreview = $path . $rows['templatepreview'];

        $array_return[] =  array('template_id' => $rows['id'],'name' => $rows['name'],'templatepreview' =>$templatepreview );
      }
    }
    if(count($result) < 50) {

        return array('template' => $array_return, 'maxreach' => 1);
    } else {
        return array( 'template' => $array_return, 'maxreach' => 0);
    }
}


function getSpecificPrintTemplate($conn_rjllearning,$template_id)
{

    $sql = "SELECT * FROM  id_cards_template  where id = ? AND status =? " ;
    $array_params = [$template_id,1];
    $stmt = $conn_rjllearning->prepare($sql);
    $stmt->execute($array_params);
    $result = $stmt->fetchAll();
 
    if(count($result) >= 1){
           $path = 'https://rejoicebilldesk.in/rjllearning_development/resources/template/students/id_cards/';
        $templatepreview = $path . $result[0]['templatepreview'];

        return  array('template_id' => $result[0]['id'],'name' => $result[0]['name'],'templatepreview' =>$templatepreview );
      
    }else{
        errorreturn("Template not found.");
    }
}