/***************************************************************************

    supportware
    Copyright (C) 2001-2007 by c.holzheuer
    c.holzheuer@sourceworx.org

    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 2 of the License, or
    (at your option) any later version.

***************************************************************************/


#ifndef DDWEBFILE_H
#define DDWEBFILE_H


#include <ddioinfo.h>
#include <ddwebcgi.h>
#include <ddmapptr.h>
#include <dditem.h>
#include <ddwebview.h>
#include <ddconfig.h>

class ddwebsite;

using namespace std;

/// ddwebfile: Ein via mutlipart/formdata hochgeladenes Bild oder Video.
/**
	ddwebfile: Ein via mutlipart/formdata hochgeladenes Bild oder Video.
	Wird umbenannt, verschoben und skaliert.
*/

class ddwebfile : public ddioinfo
{

public:

	enum dd_fileflags
	{
	  data_is_public = 1,
		data_is_removed = 2,
		data_is_alerted = 4,
		data_is_subscribed = 8,
		data_is_solved = 16,
   	data_is_closed = 32,
		data_is_draft = 64
		//...
  };
  
  ddwebfile();
	ddwebfile( const ddstring& name );
	// FIX!! state row benutzen!
	ddwebfile( const ddstring& flags, const ddstring& name, const ddstring&  path, const ddstring& width, const ddstring& height );
	 
	inline bool is_public() const 
	{
   	return ( _stateflags & ddwebfile::data_is_public );
	}
	
	inline bool is_removed() const 
	{
		return ( _stateflags & ddwebfile::data_is_removed );
	}
	
	inline bool is_alerted() const 
	{
		return ( _stateflags & ddwebfile::data_is_alerted );
	}
	
	
	inline bool is_draft() const 
	{
		return ( _stateflags & ddwebfile::data_is_draft );
	}
	
	inline bool is_private() const 
	{
		return ( _stateflags & ddwebfile::data_is_draft );
	}
	
	bool is_video_file();
	bool is_rescaled();
	
	const ddstring& get_media_size();
	const ddstring& get_media_base();
	const ddstring& get_media_type();
	const ddstring& get_media_width();	
	const ddstring& get_media_height();
	const ddstring& get_media_path();
	
	bool 						create_media_file( const char* buffer, size_t size, ddstring& rawname );
	ddstring				create_media_dir( const ddstring& targetpath, const ddstring& newfilename, ddwebcgi& cgi  );
	size_t 					resize_image_file( const ddstring& format, const ddstring appendix, const ddstring& newfilename, ddstring& newpath );
	
protected:

	void 						init_media_data();
	
	bool						_initcalled;	
	bool						_is_video_file;
	bool						_is_rescaled;
	
	size_t					_stateflags;
	size_t					_goodvotes;
	size_t					_badvotes;
	
	ddstring 				_currentpath;
	
	ddstring				_mediabase;
	ddstring				_mediasize;	
	ddstring 				_mediatype;
	ddstring 				_mediawidth;
	ddstring 				_mediaheight;
	
	
	
};


/***************************************************************************

    supportware
    Copyright (C) 2001-2007 by c.holzheuer
    c.holzheuer@sourceworx.org

    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 2 of the License, or
    (at your option) any later version.

***************************************************************************/


class ddwebfilemanager;
struct ddwebfile;

/// ddwebfilemanager: Hilfsklasse, die Kategorien speichert.
/**
	ddwebfilemanager: Hilfsklasse, die Kategorien speichert.
*/

class ddwebfilemanager : public ddmapptr<ddwebfile>
{

public:


	void init_data( ddconfig& config );
	
	void dump() const;
	
	void create_user_files( ddwebpage& pagelet, ddwebcgi& cgi );
	
	void create_image_files( ddwebpage& pagelet, ddwebcgi& cgi, const ddstring& id );
	
protected: 	
	
	void create_files( ddwebpage& pagelet, const ddstring& sitename, const ddstring& id, const ddstring& threadpath, ddwebcgi& cgi, const ddstring& prefix="" );
	
	ddwebview	_mytable;

};


/***************************************************************************

    supportware
    Copyright (C) 2001-2007 by c.holzheuer
    c.holzheuer@sourceworx.org

    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 2 of the License, or
    (at your option) any later version.

***************************************************************************/


/// sxpagefaqcategory : Hilfsklasse, die eine Kategorie abbildet.
/**
	sxpagefaqcategory, diesmal ohne  code-zauberei 
	eine direktabbildung der DB Inhalte der Kategorien-Tabelle
*/

/*
struct ddwebfile : public ddbaseobject
{

	ddstring id;
	ddstring parent;	
	ddstring name;
	ddstring key;
	ddstring title;
	ddstring path;
	ddstring idpath;
	
	ddwebfilemanager children;
	
	ddwebfile( const ddstring& aid, const ddstring& aparent, const ddstring& aname, const ddstring& akey, const ddstring& atitle )
	{
		id 		 = aid;
		parent = aparent;
		name   = aname;
		key    = akey;
		title  = atitle;
	}
	
	//void render( dditem& item, ddstring& result, int indent, bool highlight ) const;
	
	ddstring to_string() const
	{
		return "-- ID: " +  id + " Parent: " + parent + " Name: " + name + " Key: " + key; //" Title: " + title + endl;
	}
		
	void dump() const
	{
		cout << to_string() << endl; //" Title: " << title << endl;
	}
	
	
	void dump_tree() const
	{
		cout << to_string() << endl; //" Title: " << title << endl;
		for( int i=0; i<children.size(); ++i )
			children[i]->dump_tree();
	
	}
};
*/


#endif

