<?php
/*
 * Name:      Timesheet
 * Directory: timesheet
 * Version:   1.0.1
 * Type:      user
 * UI Name:   Timesheet
 * UI Icon:
 */

/*
 * Copyright (C) 2007, M2X
 *
 * Authors: Jean-Paul Saman
 *
 * 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.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

// MODULE CONFIGURATION DEFINITION
$config = array();
$config['mod_name'] = 'Timesheet';		// name the module
$config['mod_version'] = '1.0.1';		// add a version number
$config['mod_directory'] = 'timesheet';		// tell dotProject where to find this module
$config['mod_setup_class'] = 'CSetupTimesheet';	// the name of the PHP setup class (used below)
$config['mod_type'] = 'user';			// 'core' for modules distributed with dP by standard, 'user' for additional modules from dotmods
$config['mod_ui_name'] = 'Timesheet';		// the name that is shown in the main menu of the User Interface
$config['mod_ui_icon'] = 'communicate.gif';	// name of a related icon
$config['mod_description'] = 'Timesheet module for hour registrations';	// some description of the module
$config['mod_config'] = true;			// show 'configure' link in viewmods

// show module configuration with the dPframework (if requested via http)
if (@$a == 'setup') {
	echo dPshowModuleConfig( $config );
}

class CSetupTimesheet {

	function configure() {		// configure this module
		global $AppUI;
		$AppUI->redirect( 'm=timesheet&a=configure' );	// load module specific configuration page
		return true;
	}

	function remove() {
		$q = new DBQuery;

		$q->dropTable('timesheet');
		$q->exec();
		$q->clear();

		$q->dropTable('timesheet_project');
		$q->exec();	
		
		return null;
	}
	
	function upgrade( $old_version ) {
		// use this to provide upgrade functionality between different versions; not relevant here

		switch ( $old_version )
		{
		case "all":		// upgrade from scratch (called from install)
		case "0.9":
			//do some alter table commands

		case "1.0":
			return true;

		default:
			return false;
		}

		return false;
	}

	function install() {
		// prepare the creation of a dbTable
		$sql = "( " .
		  " `timesheet_id` int(11) unsigned NOT NULL auto_increment," .
		  " `timesheet_period` int(11), " .
		  " `timesheet_status` int(4) NOT NULL default '0', " .
		  " `timesheet_date` int(11) NOT NULL default '0', " .
		  " `timesheet_creator` int(11) NOT NULL default '0', " .
		  " `timesheet_worked` int(11) NOT NULL default '0', " .
		  " PRIMARY KEY  (`timesheet_id`), " .
		  " UNIQUE KEY `timesheet_id` (`timesheet_id`) " .
		  ") TYPE=MyISAM";
		$q = new DBQuery;
		$q->createTable('timesheet');
		$q->createDefinition($sql);
		$q->exec();
		db_error();
		$sql = "( " .
		  " `timesheet_queue_id` int(11) NOT NULL auto_increment, " .
		  " `timesheet_id` int(11) unsigned NOT NULL, " .
		  " `timesheet_project` int(11) NOT NULL default '0', " .
		  " `timesheet_project_amount` bigint(20) NOT NULL default '0', " .
		  " PRIMARY KEY  (`timesheet_queue_id`) " .
		  ") TYPE=MyISAM";
		$q->clear();
		$q->createTable('timesheet_project');
		$q->createDefinition($sql);
		$q->exec();
		db_error();
		return null;
	}
}

?>