<?php
$check_default_template = false;
if (!empty($_GET['dir_path'])) {
 $dir_path = $_GET['dir_path'];
 $template_file_names = [__DIR__.'/template/engine_template.php'];
} else {
 $template_file_names = [__DIR__.'/template/module_template.php'];
 return;
// $dir_path = 'modules'.DS.'ap';
}
$engine_object = [];
if (!(empty($search_result))) {
 foreach ($search_result as $object) {
  array_push($engine_object, $object);
 }
 if (!empty($pagination)) {
  $pagination->setProperty('_path', 'form');
  $pagination_statement = $pagination->show_pagination();
 }
} else if (!(empty($$class))) {
 array_push($engine_object, $$class);
} else {
 $engine = new engine();
 array_push($engine_object, $engine);
}
$all_data = [];
$file_paths = [];
$no_of_files = 0;
$dir = new RecursiveDirectoryIterator(HOME_DIR . DS . $dir_path);
$ite = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($ite, '([^\s]+(\.(?i)(inc))$)', RegexIterator::GET_MATCH);
$fileList = array();
//$module_name_a = [];
$pageno = !empty($_GET['pageno']) && !is_array($_GET['pageno']) ? $_GET['pageno'] : 1;
$per_page = (!empty($_GET['per_page']) && !is_array($_GET['per_page'])) ? $_GET['per_page'] : 50;

foreach ($files as $k1 => $file) {
// if($k1 < $min_count ){
//  continue;
// }
//  if($k1 > $max_count ){
//  break;
// }
 $file_paths[] = $file[0];
 $cm = get_class_name_from_path($file[0]);
 if(!$cm){
  continue;
 }
 $class = $cm['class_name'];
 $module_name = $cm['module_name'];

 if (property_exists($class, 'system_info') && (!empty($class::$system_info))) {
  $sys_info_a = $class::$system_info;
  $sys_info_a['obj_class_name'] = $class;
  $sys_info_a['module_name'] = $module_name;
  $sys_info_a['path'] = $file[0];
  array_push($all_data, $sys_info_a);
 }
}

$total_count = count($all_data);
$pagination = new pagination($pageno, $per_page, $total_count);
$pagination->setProperty('_path', 'form.php?');
$position = ($pageno - 1) * $per_page;

//pa($file_paths);
//pa($all_data);
?>