I, too, considered not using the friendly_url … still not sure that I will … but it was driving me crazy that this does not work! Still not sure that I am going to use this - also not sure that I’ve done it ‘right’ or what the implications may be … brand new at PHP … but here is what I have working …
PROBLEM 1: The original code did nothing with applications that exist in sec_apps but no longer exist in the project. I added a function (PHP method) to remove deleted apps:
//Array of SEC_APPS Table ===============
sc_select(rs, “SELECT app_name FROM sec_apps”);
$arr_apx = array();
while(!$rs->EOF)
{
$arr_apx[] = $rs->fields[0] ;
$rs->MoveNext();
}
$rs->Close();
//Scan the master directory
$path_parts = pathinfo($this->Ini->path_aplicacao);
$dir = $path_parts[‘dirname’];
$master_directory = array_diff(scandir($dir), array(’…’, ‘.’, ‘_lib’));
//Difference between the two
$arr_gone=array_diff($arr_apx, $master_directory) ; //Records deleted from the project
foreach ($arr_gone as $k => $vc_gone)
{
//delete those records from sec_groups_apps
$sql = “DELETE from sec_groups_apps WHERE app_name = ‘$vc_gone’” ;
sc_exec_sql($sql);
//delete those records from sec_apps
$sql = "DELETE from sec_apps WHERE app_name = '$vc_gone'" ;
sc_exec_sql($sql);
}
PROBLEM 2:App_type was not getting populated in the sec_apps table and I was not able to apply insert, update, delete privileges to those applications. (As it turns out, it does not use the first 4 characters like I originally thought - but the 4th line of the ini file in the application directory). Essentially, I put a ‘foreach’ inside a ‘foreach’:
//Remove apps that are no longer in the project
remove_deleted_apps();
//Array of GROUPS ================
$arr_grp = array();
sc_select(rs, “SELECT group_id FROM sec_groups”);
while(!$rs->EOF)
{
$arr_grp[] = $rs->fields[0];
$rs->MoveNext();
}
$rs->Close();
//Array of SEC_APPS Table ini files ===============
sc_select(rs, “SELECT app_name FROM sec_apps”);
$arr_apps_db = array();
while(!$rs->EOF)
{
$arr_apps_db[] = $rs->fields[0] . ‘_ini.txt’;
$rs->MoveNext();
}
$rs->Close();
//Array of INI files in the friendly_url directory
$arr_friendly = array_diff(scandir($this->Ini->path_aplicacao . “…/_lib/friendly_url/”), array(’.’,’…’));
foreach($arr_friendly as $k => $vc_ininame)
{
//Get appname and dirname from friendly array
$app = substr($vc_ininame, 0, -8);
$friendly_name = file_get_contents($this->Ini->path_aplicacao . “…/_lib/friendly_url/”. $app . ‘_ini.txt’);
$proj_name = ’ ’ ;
$app_type = ’ ’ ;
//omit mobile apps
if(substr($app, -4) == '_mob' && file_exists($this->Ini->path_aplicacao . "../_lib/friendly_url/". substr($app, 0, -4) . "_ini.txt"))
{
unset($arr_friendly[$k]);
continue;
}
//Scan the master directory
$path_parts = pathinfo($this->Ini->path_aplicacao);
$dir = $path_parts['dirname'];
$master_directory = array_diff(scandir($dir), array('..', '.', '_lib'));
//Difference between the master directory and sec_apps
$arr_apps = array_diff($master_directory, $arr_apps_db);
//This gives me what I want
foreach($arr_apps as $k => $app_name)
{
//Get apptype from ini file in master directory
$file_ini = $this->Ini->path_aplicacao. "../".$app_name . "/". $vc_ininame;
if(is_file($file_ini))
{
$lines = file($file_ini);
if(isset($lines[4]))
$app_type = trim($lines[4]);
if(isset($lines[1]))
$proj_name = trim($lines[1]) ;
$sql = "SELECT count(*) FROM sec_apps WHERE app_name = '". $app_name ."' ";
sc_lookup(rs, $sql);
if({rs[0][0]} == 0)
{
$sql = "INSERT INTO sec_apps(app_name, app_type) VALUES ('". $app_name ."', '".$app_type."')";
sc_exec_sql( $sql );
foreach($arr_grp as $grp)
{
$sql = "INSERT INTO sec_groups_apps(app_name, group_id) VALUES ('". $app_name ."', '". $grp ."')";
sc_exec_sql( $sql );
}
}
}
} //end 2nd foreach loop
} //end first foreach loop