<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

define('ISWIZARDS', true);
include_once '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'constants.php';


SecurityOperations::PurgeInput(true);


class ListWizards extends Wizard
{
  
  public function __construct()
  {
    $this->wizardName = 'List Wizards';
    $this->wizardDescription = 'Dieser Wizard listet alle zur Verfügung stehenden Wizards auf.';
  }

  
  public function getWizardSubDirs($pPath)
  {
    $pPath = $pPath . '/';
    $ary = array();
    $handle = opendir($pPath); 
    while ($file = readdir($handle)) { 
      if ($file != '.' && $file != '..' and is_dir($pPath . $file)) { 
        if (file_exists($pPath . $file . '/wizard.ini')) { 
          array_push($ary, $file);
        } 
      }
    }
    closedir($handle); 

    return $ary;
  }

  
  public function _getWizardBody()
  {
    $return = "<p class='font wizardbody'>Bitte klicken Sie auf den Namen eines Wizards, um ihn zu starten.</p>" . BR_WT . "\n";
    $ary = $this->getWizardSubDirs('.');
    foreach ($ary as $dir) {
      $iniary = parse_ini_file($dir . '/wizard.ini');
      $return .= "<div class='wizardlistlink'><a class='font link wizardbody' href='./" . CleanOperations::cleanStringForHtml($dir) . "'>";
      $return .= $iniary['Name'] . "</a></div><div class='wizardlistdesc'><font class='font wizardbody'>";
      $return .= $iniary['Description'] . '</font></div>' . BR_WT . "\n";
    }

    return $return;
  }

  
  public function getWizardFooter() 
  {
    return '';
  }
}

$wizard = new ListWizards();
$wizard->start('wizard.css');