<?php
/************************************************
*	organigram plugin file							*
*	file: plugin_organigram.php						*
*	version: 1.0								*
*	date: 31/05/2010							*
*	author: Portaneo							*
*												*
************************************************/

/*
 * name: Plugin organigram
 * description: Plugin organigram
 * dependencies: no
 * author: Portaneo
 */
 
define("organigram_NAME","plugin organigram"); 

 
/*
  * Registers the action in order to install and uninstall the plugin
  */
 register_hook('install_plugin_organigram/plugin_organigram','pluginorganigram_install');
 register_hook('uninstall_plugin_organigram/plugin_organigram','pluginorganigram_uninstall');
 register_hook('userinterface_header','loadorganigramjs',5,0);

 
function loadorganigramjs(){
	echo '<link rel="stylesheet" type="text/css" href="../includes/plugins/plugin_organigram/styles/organigram.css" />';
	echo "<script type='text/javascript' src='../includes/plugins/plugin_organigram/includes/organigram.js'></script>";
	echo '<script type="text/javascript" src="../includes/plugins/plugin_organigram/l10n/'.__LANG.'/lang.js?v='.__POSHVERSION.'" ></script>';
	/*echo "<script type='text/javascript' src='../includes/plugins/plugin_organigram/l10n/".__LANG."/lang.js'></script>";*/
}

/*
  * Install function
  */
function pluginorganigram_install() {
	global $DB;
	$sql = "SELECT id FROM applications WHERE title='organigram'";
	$links = $DB->select(FETCH_OBJECT,$sql);
	if (empty($links)){
		$sql = "INSERT INTO applications (title,description,creation_date,icon,action) VALUES ('organigram','',CURRENT_DATE,'../includes/plugins/portaneo_project_mgr/images/menu_icon.gif','organigram.open()')";
		$DB->execute($sql);
	}
	$DB->freeResults();
	$sql = "CREATE TABLE `users_hierarchy` (`user_id` INT( 101 ) NOT NULL ,`manager_id` INT( 10 ) NOT NULL ,`branch` VARCHAR( 255 ) NOT NULL ) ENGINE = MYISAM ; ";
	$DB->execute($sql);
}

/*
  * Uninstall function
  */
function pluginorganigram_uninstall() {
	// do not suppress table, they can contain important information !!
	global $DB;
	$sql = "DELETE FROM applications WHERE title='organigram' ";
	$DB->execute($sql);
    $sql = "DROP TABLE IF EXISTS `users_hierarchy`;";
	$DB->execute($sql);
}


?>