/**
* difference in the names of files and folders from selected folders
* copyright : (c) 2014 Andrzej Krokos
* version PHP : 5
* author : shreker983@gmail.com
* licence : GPL
*
*/
class diff_data
{
function set_data($directory) // set data
{
$this->directory = $directory;
}
function dir_to_array($directory) // listing folder
{
{
{
while (false !== ($entry = readdir($handle)))
{
if ($entry == '.' || $entry == '..')
{
continue;
}
$data[] = $entry;
}
return $data;
}
}
else
{
echo '<div style="font-family:arial; text-align:center; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">error: could not open dir "'.$this->directory.'" !</div>';
return false;
}
}
function get_data($type, $folder1, $folder2) // get manipulation data
{
$mdata = ($type == 'ai') ?
array_intersect($this->dir_to_array($folder1), $this->dir_to_array($folder2)) : array_diff($this->dir_to_array($folder1), $this->dir_to_array($folder2));
return $mdata;
}
function show_data($ret, $type, $folder1, $folder2) // show data
{
$cdata = count($this->get_data($type, $folder1, $folder2));
if ($ret == 'd')
{
foreach($this->get_data($type, $folder1, $folder2) as $f) // names to data
{
echo '<strong>'.$f.'</strong><em> ('.(is_file($folder1.'/'.$f) ?
'file' : 'folder').')</em><br />';
}
}
else
{
echo '<pre>';
var_dump($this->get_data($type, $folder1, $folder2)); // names to array
echo '</pre>';
}
echo '<div style="font-weight:bold;'.(($cdata == 0) ? ' text-align:center; color:red;' : ' text-align:right;').' padding:10px 5px 5px 5px;">'.(($cdata == 0) ? 'no data !' : 'all : '.$cdata.' pcs.').'</div>';
}
function get_form() // show form
{
$post_data = array('folder1', 'folder2', 'type', 'show');
foreach ($post_data as $name)
{
$_POST[$name] = isset($_POST[$name]) ?
$_POST[$name] : '';
}
echo '<div style="vertical-align:left; padding: 5px 5px 5px 5px;">';
echo '<fieldset>';
echo '<legend>difference in the names of files and folders from selected folders</legend>';
if (!isset($_POST['nfolder']))
{
echo '<form name="" action="" method="post">';
echo '<p><label for="name">folder (root) :</label><select class="" name="folder1" id="folder1" style="vertical-align:middle; width:250px; margin-left:5px;">';
echo '<option value="" selected="selected">select ...</option>';
foreach(glob($this->directory.'*', GLOB_ONLYDIR
) as $dir1)
{
echo '<option value="'.$dir1.'" '.(($dir1 == $_POST['folder1']) ? 'selected' : '').'>'.$dir1.'</option>'; // select folder - root
}
echo '</select></p>';
echo '<p><label for="name">folder (comp.) :</label><select class="" name="folder2" id="folder2" style="vertical-align:middle; width:250px; margin-left:5px;">';
echo '<option value="" selected="selected">select ...</option>';
foreach(glob($this->directory.'*', GLOB_ONLYDIR
) as $dir2)
{
echo '<option value="'.$dir2.'" '.(($dir2 == $_POST['folder2']) ? 'selected' : '').'>'.$dir2.'</option>'; // select folder - comp.
}
echo '</select></p>';
echo '<p><label for="name">compare :</label><select class="" name="type" style="vertical-align:middle; width:200px; margin-left:5px;">';
echo '<option value="" selected="selected">select ...</option>';
$type = array('ai' => 'repeated files', 'ad' => 'difference files');
foreach($type as $vt => $namet)
{
echo '<option value="'.$vt.'"'.($vt == $_POST['type'] ? ' selected="selected"' : '').'>'.$namet.'</option>'; // select
}
echo '</select></p>';
echo '<p><label for="name">data (return) :</label><select class="" name="show" style="vertical-align:middle; width:200px; margin-left:5px;">';
echo '<option value="" selected="selected">select ...</option>';
$show = array('a' => 'names to array', 'd' => 'names to data');
foreach($show as $vs => $names)
{
echo '<option value="'.$vs.'"'.($vs == $_POST['show'] ? ' selected="selected"' : '').'>'.$names.'</option>';
}
echo '</select></p>';
echo '<div style="text-align:center; padding:5px 5px 5px 5px;"><input type="submit" name="nfolder" value="SELECT" class="przycisk" onclick="return confirm('are you sure?')" style="margin-left:5px; vertical-align:middle;" /></div>';
echo '</form>';
}
else
{
if (empty($_POST['folder1']) || empty($_POST['folder2']) || empty($_POST['type']) || empty($_POST['show']))
{
echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">select data !</div>';
}
{
echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">incorrect folder path !</div>';
}
{
echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">incorrect folder path !</div>';
}
else if ($_POST['folder1'] == $_POST['folder2'])
{
echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">both paths are identical !</div>';
}
{
echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">select the type of comparison !</div>';
}
{
echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">select the type for displaying result !</div>';
}
else
{
echo '<div style="vertical-align:left; padding:5px 0px 0px 0px;">';
$this->show_data($_POST['show'], $_POST['type'], $_POST['folder1'], $_POST['folder2']);
echo '</div>';
}
echo '<div style="vertical-align:left; padding: 5px 5px 5px 5px;">';
echo '<form action="'.$_SERVER['HTTP_REFERER'].'" method="post">';
echo '<div style="text-align:center; padding:5px 5px 5px 5px;"><input type="submit" name="back" value="BACK" /></div>';
echo '</form>';
echo '</div>';
}
echo '<div style="text-align:center; font-family:verdana; color:black; font-size:10px; font-weight:normal; padding:5px 5px 5px 5px;">design by sid © 2004 - '. date('Y').'</div>';
echo '</fieldset>';
echo '</div>';
}
}
// example
$dd = new diff_data();
$dd->set_data('./');
$dd->get_form();