$jsservice_dir = "../../app/services/";
if (!file_exists($htmlmain_dir)) {
    mkdir($htmlmain_dir, 0755);
}
if (!file_exists($htmlview_dir)) {
    mkdir($htmlview_dir, 0755);
}
if (!file_exists($jscontrol_dir)) {
    mkdir($jscontrol_dir, 0755);
}
if (!file_exists($jsservice_dir)) {
    mkdir($jsservice_dir, 0755);
}
// = = = = = = = = = = = = = = = = = =
// MAIN APP FILE
$appclass_file = $fo->OpenFile('../template/', 'app.js.tmpl', 'r');
$appclass_content = $fo->FileContent($appclass_file);
$appclass_content = preg_replace('/PATAPICONFIGPAT/', "http://localhost/{$appname}/api/index.php/", $appclass_content);
$appclass_content = preg_replace('/PATAPPNAMEPAT/', $appname, $appclass_content);
//
// MAIN INDEX.HTML
$appindex_file = $fo->OpenFile('../template/', 'index.html.tmpl', 'r');
$appindex_content = $fo->FileContent($appindex_file);
$appindex_content = preg_replace('/PATAPPNAMEPAT/', $appname, $appindex_content);
// MENU.HTML
$html_menu_file = $fo->OpenFile('../template/', 'menu.html.tmpl', 'r');
$html_menu_content = $fo->FileContent($html_menu_file);
#################################
# CLASS AND COMPONENTS CREATION
#################################
printf($scaffold->classComCreateMessage);
    unset($fields);
    unset($fieldcount);
    unset($fieldtext);
    unset($fieldname);
    unset($fieldtype);
    unset($field_list);
    unset($create_query);
}
printf($scaffold->openFileClassMessage);
require_once "../utils/Fileoperation.php";
$fo = new Fileoperation();
//DEFINE LOCATIONS TO PUT GENERATED FILES
$slimapp_dir = "../../api/";
$slimmodel_dir = "../../api/model/";
// MAIN APP FILE
$appclass_file = $fo->OpenFile('../template/', 'slim_index.php.tmpl', 'r');
$appclass_content = $fo->FileContent($appclass_file);
$appdbconfig = "R::setup('mysql:host=localhost;dbname=" . DATABASE_NAME . "','" . DATABASE_USERNAME . "','" . DATABASE_PASSWORD . "');";
$appclass_content = preg_replace('/PATDBCONFIGPAT/', $appdbconfig, $appclass_content);
#################################
# CLASS AND COMPONENTS CREATION
#################################
printf($scaffold->classComCreateMessage);
/*
LOOP OVER ALL TABLES DEFINED IN YAML FILE
THIS WILL LOOP ON EVERY TABLE ON THE YAML CONFIG.
I.E. IT WILL LOOP 3 TIMES IF THERE ARE 3 TABLES IN THE CONFIG.
THE LOOP INSIDE A TABLE (COLUMN LOOP) HAPPENS INSIDE THIS MAIN LOOP.
*/
$appmodel_inclusion = "";
$SLIMROUTERS = "";
//

// MAIN INDEX.HTML
$appindex_file 		= $fo->OpenFile('../template/','index.html.tmpl','r');
$appindex_content 	= $fo->FileContent($appindex_file);

$appindex_content  	= preg_replace('/PATAPPNAMEPAT/', $appname, $appindex_content);

// MENU.HTML
$html_menu_file 	= $fo->OpenFile('../template/','menu.html.tmpl','r');
$html_menu_content 	= $fo->FileContent($html_menu_file);
*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// MAIN FILE
$main_file = $fo->OpenFile('../template/', 'ng_standalone.html.tmpl', 'r');
$main_content = $fo->FileContent($main_file);
#################################
# CLASS AND COMPONENTS CREATION
#################################
printf($scaffold->classComCreateMessage);
/*
LOOP OVER ALL TABLES DEFINED IN YAML FILE
THIS WILL LOOP ON EVERY TABLE ON THE YAML CONFIG.
I.E. IT WILL LOOP 3 TIMES IF THERE ARE 3 TABLES IN THE CONFIG.
THE LOOP INSIDE A TABLE (COLUMN LOOP) HAPPENS INSIDE THIS MAIN LOOP.
*/
//LOOPED VALUES STRING: LEVEL 1
$html_classinjections = "";
$html_viewroutes = "";
$html_controllerfiles = "";