<?  // PHPmyGallery - backend core - groups setup

/* File description:

This script stores names for the existing groups directories.

### What this script does:
###
### Included from: adminmenu.index.php
### |
### | (Uses templates from adminmenu/groupssetup)
### +- Setup          (Load Groupnames, Modify names, Save to DB, display Result)
###
*/ 

// Set max-sizes for input elements
$pktpl_vars['text_formelementSize']      = '40';
$pktpl_vars['text_formelementMaxlength'] = '200';

// Load settings for all galleries
if(allocateData('groupssetup'))
    $groupsConf = getData('groupssetup');

// Make header templates
$pktpl_vars['text_headline']                           = $l['groups_settings'];
$pktpl_vars['template_admin_groupssetupTableHeadline'] = pktpl('adminmenu/groupssetup/TableHeadline.html');

// Genrate HTML form out of $galleryconfig_items
$tmp    = '';
$groups = filenames2arr($conf['pathToGroups'], GROUPS);
foreach($groups as $g) {
    
    if($saveit=='save_it_baby' && isset($_POST[$g])) {
        $groupsConf[$g] = $_POST[$g];
    } // if
    
    $pktpl_vars['group_dir']            = $g;
    $pktpl_vars['text_formelementName'] = $g;
    if(isset($groupsConf[$g]))
        $pktpl_vars['text_formelementValue'] = $groupsConf[$g];
    else
        $pktpl_vars['text_formelementValue'] = str_replace('_',' ',$g);
    
    $pktpl_vars['template_all_forminputText'] = pktpl('all_forminputText.html');
    
    $tmp .= pktpl('adminmenu/groupssetup/TableRow.html');
    
} // foreach();
$pktpl_vars['template_admin_groupssetupTableRow'] = $tmp;

// Write Config if form has been submitted
if ($saveit=='save_it_baby') {
    $erg = putData($groupsConf,'groupssetup');
    
    // Assign success vars (may change in later version to be more exact)
    switch($erg) {
        case -1: // is_writable returns false
            $pktpl_vars['text_headline'] = $dbEntryName.$l['error.writefile_not_writable'];
        break;
        case -2: // fopen() failed
            $pktpl_vars['text_headline'] = $dbEntryName.$l['error.writefile_fopen_failed'];
        break;
        case -3: // fwrite() failed
            $pktpl_vars['text_headline'] = $dbEntryName.$l['error.writefile_fwrite_failed'];
        break;
        case -4: // internal error
            $pktpl_vars['text_headline'] = $dbEntryName.$l['error.writefile_internal_error'];
        break;
        case 0:
        default: // success!
            $pktpl_vars['text_headline'] = $l['success.writefile_saved'];
        break;
    } // switch
    
    // Success Box template
    $pktpl_vars['template_admin_successBox']      = pktpl('adminmenu/admin_successBox.html');
} // if

// Final templates
$pktpl_vars['template_admin_groupssetupTableFormsubmit'] = pktpl('adminmenu/groupssetup/TableFormsubmit.html');
$pktpl_vars['template_admin_table']                      = pktpl('adminmenu/groupssetup/Table.html');

?>