#!/usr/clearos/sandbox/usr/bin/php
<?php

/**
 * ClearOS Photo Organizer script.
 *
 * @category   apps
 * @package    photo-organizer
 * @subpackage scripts
 * @author     ClearFoundation <developer@clearfoundation.com>
 * @copyright  2008-2011 ClearFoundation
 * @license    http://www.gnu.org/copyleft/gpl.html GNU General Public License version 3 or later
 * @link       http://www.clearfoundation.com/docs/developer/apps/photo_organizer/
 */

///////////////////////////////////////////////////////////////////////////////
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// B O O T S T R A P
///////////////////////////////////////////////////////////////////////////////

$bootstrap = getenv('CLEAROS_BOOTSTRAP') ? getenv('CLEAROS_BOOTSTRAP') : '/usr/clearos/framework/shared';
require_once $bootstrap . '/bootstrap.php';

///////////////////////////////////////////////////////////////////////////////
// T R A N S L A T I O N S
///////////////////////////////////////////////////////////////////////////////

clearos_load_language('base');
clearos_load_language('photo_organizer');

///////////////////////////////////////////////////////////////////////////////
// D E P E N D E N C I E S
///////////////////////////////////////////////////////////////////////////////

// Classes
//--------

use \clearos\apps\photo_organizer\Photo_Organizer as Photo_Organizer;

clearos_load_library('photo_organizer/Photo_Organizer');

// Exceptions
//-----------

use \Exception as Exception;

///////////////////////////////////////////////////////////////////////////////
// M A I N
///////////////////////////////////////////////////////////////////////////////

//--------------------------------------------------------------------
// Command line options
//--------------------------------------------------------------------

$short_options  = '';

// Common
$short_options .= 'p::'; // Path
$short_options .= 'r::'; // Recurse
$short_options .= 'm::'; // Move
$short_options .= 'h';   // Help

$helpopts  = '
  Common Options
  --------------
  -p=override sources by prividing path (eg. /tmp)
  -r=recurse directory if override source is set
  -m=move files if override source is set
  -h: help
';

// Handle command line options
//----------------------------

$options = getopt($short_options);

$path = isset($options['p']) ? $options['p'] : NULL;
$recurse = isset($options['r']) ? TRUE : FALSE;
$move = isset($options['m']) ? TRUE : FALSE;
$help = isset($options['h']) ? TRUE : FALSE;

if ($help) {
    echo "usage: " . $argv[0] . " [options]\n";
    echo $helpopts;
    exit(0);
}

$photo_organizer = new Photo_Organizer();

try {
    $source = NULL;
    if ($path != NULL) {
        $source = array(
            'id' => 0,
            'path' => $path,
            'move' => $move,
            'recurse' => $recurse
        );
    }
    $photo_organizer->run($source);
    exit(0);
} catch (Exception $e) {
    echo clearos_exception_message($e) . "\n";
    exit(1);
}

// vim: syntax=php
