<?php
/********** Settings like in PHPmyGallery 1.0 **********/
// Change these if you altered the file
// phpmygallery.core_setup.php in your 1.0 installation

// Filename of the file which holds picture descriptions in each directory
$picture_describefile = 'index.php';

// Filename of config files for single galleries
$conffile             = 'gallery.config.php';


/**************** The plug-in script *******************/

// Get GET vars
$convert_group   = $_GET['group'];
$convert_gallery = $_GET['gallery'];

// Read language pack for this PlugIn
processLanguagePack('GalleryConvertor',$conf['lang'],'English');


// Convert a gallery
if($group != '' && $gallery != '') {
    // Convert picture descriptions
    if(file_exists($conf['pathToGroups'].$group.'/'.$gallery.'/'.$picture_describefile)) {
        include($conf['pathToGroups'].$group.'/'.$gallery.'/'.$picture_describefile);
        
        $newArr = array();
        foreach($picset as $k=>$v) {
            if($k == 'pagetitle') {
                $newArr[0]['pagetitle'] = $picset['pagetitle'];
            }
            else {
                $newArr[1][$k]['fullname'] = $v['fullname'];
                $newArr[1][$k]['fulltext'] = $v['fulltext'];
            }
        } // foreach
        
        // Save the new settings
        putData($newArr,'picsdescriptions',$group.'--.--'.$gallery);
    } // if
    
    // Convert gallery settings
    if(file_exists($conf['pathToGroups'].$group.'/'.$gallery.'/'.$conffile)) {
        include($conf['pathToGroups'].$group.'/'.$gallery.'/'.$conffile);
        
        $newArr = array();
        $newArr['lang']             = $conf['lang'];
        $newArr['use_htmlTable']    = $conf['use_htmlTable'];
        $newArr['usethumbs']        = ($conf['usethumbs']) ? 'true': 'false';
        $newArr['useprevnext']      = ($conf['useprevnext']) ? 'true': 'false';
        $newArr['prefix_or_suffix'] = $conf['prefix_or_suffix'];
        $newArr['thumb_prefix']     = $conf['thumb_prefix'];
        $newArr['thumb_suffix']     = $conf['thumb_suffix'];
        
        // Save the new settings
        putData($newArr,'gallerysettings',$group.'--.--'.$gallery);
    } // if
} // if

// Pace through all groups and galleries
$groups = filenames2arr($conf['pathToGroups'],GROUPS);
$pktpl_vars['table_rows'] = '';
foreach($groups as $g) {
    $pktpl_vars['group_name']  = $g;
    $pktpl_vars['table_rows'] .= pktpl('plugins/GalleryConvertor/tablerow_group.html');
    
    $galleries = filenames2arr($conf['pathToGroups'].$g.'/',DIRECTORIES);
    foreach($galleries as $gallery) {
        
        $pktpl_vars['gallery_name'] = $gallery;
        
        // Look up if converting is necessary
        $settingsExist1     = false;
        $descriptionsExist1 = false;
        $settingsExist2     = false;
        $descriptionsExist2 = false;
        
        // Look up for 1.0+ galleries
        if(file_exists($conf['pathToGroups'].$g.'/'.$gallery.'/'.$conffile))
            $settingsExist1 = true;
        
        if(file_exists($conf['pathToGroups'].$g.'/'.$gallery.'/'.$picture_describefile))
            $descriptionsExist1 = true;
        
        // Look up for 1.5 Gold galleries
        if(allocateData('gallerysettings',$g.'--.--'.$gallery))
            $settingsExist2 = true;
        
        if(allocateData('picsdescriptions',$g.'--.--'.$gallery))
            $descriptionsExist2 = true;
        
        
        // Display an OK or a "convert" link
        if(($settingsExist1     == $settingsExist2     || $settingsExist2) &&
           ($descriptionsExist1 == $descriptionsExist2 || $descriptionsExist2)) {
            
            $pktpl_vars['gallery_info'] = pktpl('plugins/GalleryConvertor/text_ok.html');
        } // if
        else {
            
            $pktpl_vars['link_convert'] = '&group='.urlencode($g).'&gallery='.urlencode($gallery);
            $pktpl_vars['gallery_info'] = pktpl('plugins/GalleryConvertor/link_convert.html');
            
        } // else
        
        $pktpl_vars['table_rows'] .= pktpl('plugins/GalleryConvertor/tablerow_gallery.html');
        
    } // foreach (galleries of this group)
} // foreach (groups)

$pktpl_vars['template_admin_table'] = pktpl('plugins/GalleryConvertor/main.html');

?>
