Location: PHPKode > projects > EXtensible Production Suite (XPS) > xpsdev/core/controls/api.php
<?php
/***********************************************************************************************************
*
* <p>Contains system API</p>
*
* @author heidtc < hide@address.com >, cookbt < hide@address.com >, rennemannt <hide@address.com>
*
************************************************************************************************************/
Class API
{
	//instance variables
    private $debug;

	public $DC; //Database Controller
	public $MC; //Message Controller
	public $SC; //Settings Controller
    public $WC; //Widget Controller
    public $Smarty; //Smarty object, passed by reference.
    public $message; //Message stores method status messages.
    public $error_count; //Error count stores the number of errors encountered.
    public $output2display = ''; //Smarty template file to be loaded/displayed.

	/***************************************************
	* <p>Constructor for core API control.</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >, rennemannt <hide@address.com>
	***************************************************/
	public function __construct($debug=false)
	{
        $this->debug = $debug;
        if($debug) echo 'API::__construct()<br/>';

		require_once( CONTROLS . '/setting_control.php' );
		$this->SC = new Setting_Control($debug);
		require_once( CONTROLS . '/message_control.php' );
		$this->MC = new Message_Control($this->SC, $debug);
		require_once( CONTROLS . '/database_control.php' );
		$this->DC = new Database_Control($this->SC, $this->MC, $debug);
        require_once(CONTROLS .'/widget_control.php');
		$this->WC = new Widget_Control($this->DC, $this->MC);
        require_once(CONFIGS . '/smarty_connect.php');
        $this->Smarty = new Smarty_Connect();
        $this->Smarty->register_object('API', $this);
        $this->message = '';
        $this->output2display = '';
        $this->error_count = 0;
	}


/*********************************************************************
*                          PRIVATE FUNCTIONS	                     *
*********************************************************************/

	/***************************************************
	* <p>check for admin status</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	***************************************************/
	private function admin_check()
	{
		if( !isset($_SESSION['is_admin']) or  ($_SESSION['is_admin']!=true ) )
		{
			$message = $this->MC->get_message('hacking_message','core');
			$message = $this->get_styled_message($message, 1);
			$this->get_widgets();
			$this->launch_core_module( array('module_id' => 'Home', 'MESSAGE'=>$message) );
			$this->Smarty->assign('theme_body', '../../themes/'.$this->get_theme().'/body.tpl');
			$this->Smarty->assign('module_output', $this->output2display);
			$this->Smarty->display('core.tpl');
			die();
		}
	}

/*********************************************************************
*                          API FUNCTIONS	                         *
*********************************************************************/

    /*******************************************************
    * <p>get_styled_message</p>
    *
    * @access   public
    * @author 	rennemannt <hide@address.com>
    * @param	none
    * @return	styled message
    ********************************************************/
    public function get_styled_message($message, $error_count)
    {
        $this->Smarty->assign('message', $message);
        $this->Smarty->assign('error_count', $error_count);
        $styled_message = $this->Smarty->fetch('_message.tpl');
        return $styled_message;
    }


	/*******************************************************
	* <p>TODO: Name of function</p>
	*
	* @access   public
	* @author 	rennemannt <hide@address.com>
	* @param	array [$params] array of parameters.
	* @return	boolean true/false.
	********************************************************/
	public function get_setting_options($params)
	{
	    $options = array();
	    $options = $this->SC->get_setting_options($params);
	    $this->Smarty->assign('id', $params['id']);
	    $this->Smarty->assign('options', $options);
	    return $this->Smarty->fetch('_html_options.tpl');
	}

	/*******************************************************
	* <p>retrives a message</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	array [$params] array of parameters
	* @return	string message
	********************************************************/
	public function get_message($params)
	{
        if($this->debug) echo 'API::get_message()<br/>';
		//rip params
		$message_id = $params['message_id'];
		$file_location = 'core';
		if(isset($params['file_location']) )
		{
			$file_location = $params['file_location'];
		}
		//do function calls
		return $this->MC->get_message($message_id, $file_location);
	}

	/*******************************************************
	* <p>retrives a message</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	array [$params] array of parameters
	* @return	string message
	********************************************************/
	public function get_label($params)
	{
        if($this->debug) echo 'API::get_label()<br/>';
		//rip params
		$file_location = 'core';
		$label_id = $params['label_id'];
		if(isset($params['file_location']) )
		{
		 	$file_location = $params['file_location'];
		}
		//do function calls
		return $this->MC->get_label($label_id, $file_location);
	}

	/*******************************************************
	* <p>retrieves a setting value</p>
	*
	* @access	public
	* @author	Brian Cook < hide@address.com >
	* @param	$params['file_location'] the location of the setting file
	* @param	$params['setting_id'] the id value of the setting in the file
	* @return	string setting value
	********************************************************/
	public function get_setting($params)
	{

		if($this->debug) echo 'API::get_setting()<br/>';
	 	$file_location = 'core';
	 	if(isset($params['file_location']))
	 	{
	 		$file_location = $params['file_location'];
	 	}
		return $this->SC->get_setting($params['setting_id'], $file_location);
	}

	/*******************************************************
	* <p>alters the value of a setting</p>
	*
	* @access	public
	* @author	Brian Cook < hide@address.com >
	* @param	$params['setting_id'] the id value of the setting in the file
	* @param	$params['value'] the new value of the setting
	* @param	$params['file_location'] the location of the setting file
	********************************************************/
	public function set_setting($params)
	{
		$this->admin_check();

		$file_location = 'core';
		if(isset($params['file_location']))
		{
			$file_location = $params['file_location'];
		}
		return $this->SC->set_setting($params['setting_id'], $params['value'], $file_location);
	}

	/*******************************************************
	* <p>downloads a file</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	array [$params] array of parameters
	* @return	boolean
	********************************************************/
	public function download_file($params)
	{
		//rip params
		$file_id = $params['file_id'];
		if(isset($params['table_name']) )
			$table_name = $params['table_name'];
		else
			$table_name = 'core';

		//create objects
		require_once( CONTROLS . '/file_control.php' );
		$File_Control = new File_Control($this->DC, $this->MC);

		//do function calls
		return $File_Control->download($file_id, $table_name);
	}

	/*******************************************************
	* <p>downloads a file</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	array [$params] array of parameters
	* @return	boolean
	********************************************************/
	public function upload_file($params)
	{
		//rip params
		if(isset($params['table_name']) )
			$table_name = $params['table_name'];
		else
			$table_name = 'core';

		//create objects
		require_once( CONTROLS . '/file_control.php' );
		$File_Control = new File_Control($this->DC, $this->MC);

		//do function calls
		return $File_Control->upload($table_name);
	}


/////////////////////////////
///////    WIDGETS    ///////
/////////////////////////////

	/**********************************************************************
	* <p>Show all widgets</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >, Brian Cook < hide@address.com >
	* @param	array [$params] array of parameters
	* @return	none
	**********************************************************************/
	public function get_widgets($params = array())
	{
		$widgets = $this->WC->show_all_widgets($this, $params);
        $this->Smarty->assign('widgets', $widgets);
	}

	/**********************************************************************
	* <p></p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	array [$params] array of parameters
	* @return	none
	**********************************************************************/
	public function update_widget_content($params = array())
	{
		$widget_id = $params['widget_id'];
		$all_widgets = $this->WC->show_all_widgets($this, $params);
		$output = $all_widgets[$widget_id]['content'];
		die($output);
	}

	/**********************************************************************
	* <p></p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	array [$params] array of parameters
	* @return	none
	**********************************************************************/
	public function update_inactive_widgets_container($params = array())
	{
		$widgets = $this->WC->show_all_widgets($this, $params);
		$this->Smarty->assign('widgets', $widgets);
		$output = $this->Smarty->fetch("inc_inactive_widget_container.tpl");
		die($output);
	}

	/**********************************************************************
	* <p>Log position changes</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	array [$params] array of parameters
	* @return	none
	**********************************************************************/
	public function log_position_change($params = array())
	{
		$output = $this->WC->log_position_changes($params);
		die($output);
	}

	/*******************************************************
	********************************************************/
	public function activate_module_widgets($params = array())
	{
		$output = $this->WC->activate_module_widgets($params['MODULE_ID']);
		die($output);
	}

	/*******************************************************
	********************************************************/
	public function deactivate_module_widgets($params = array())
	{
		$output = $this->WC->deactivate_module_widgets($params['module_id']);
		die($output);
	}

/////////////////////////////
///////    MODULES    ///////
/////////////////////////////

	/*******************************************************
	********************************************************/
	public function launch_module($params)
	{
		$template_dir = $this->Smarty->template_dir;
        $mod_id = $params['module_id'];
		require_once(MODULES. '/' . $mod_id .'/' . $mod_id . '.php');
		$Module = new $mod_id($this, $params);
		$output = $Module->output;
		$this->output2display = $output;
        $this->Smarty->template_dir = $template_dir;
	}

	/*******************************************************
	********************************************************/
	public function launch_core_module($params)
	{
		//Breadcrumbs
		$breadcrumbs = $this->MC->get_breadcrumbs('launchCoreModule',$params);
		$this->Smarty->assign('breadcrumbs', $breadcrumbs);

		//Messaging
		if(isset($params['MESSAGE']))
		{
			$this->Smarty->assign('message', $params['MESSAGE']);
		}

		/***************
		* Core Modules *
		***************/

		//HOME MODULE
		if($params['module_id'] == 'Home')
		{
			if(isset($params['child_id']))
			{
				//contact panel
				if($params['child_id']=='ContactInfo')
				{
					$output = $this->Smarty->fetch('mod_footer_contact.tpl');
				}
				//privacy policy panel
				elseif($params['child_id']=='PrivacyPolicy')
				{
					$output = $this->Smarty->fetch('mod_footer_privacy.tpl');
				}
				//usage terms panel
				elseif($params['child_id']=='UsageTerms')
				{
					$output = $this->Smarty->fetch('mod_footer_terms.tpl');
				}
				//accessibility panel
				elseif($params['child_id']=='Accessibility')
				{
					$output = $this->Smarty->fetch('mod_footer_accessibility.tpl');
				}
			}
			else
			{
				$output = $this->Smarty->fetch("default.tpl");
			}
		}

		//MODULE ADMIN MODULE
		elseif($params['module_id'] == 'ModuleAdmin')
		{
			require_once(CONTROLS .'/module_control.php');
			$ModC = new Module_Control($this->DC, $this->MC, $this->SC);

			if(isset($params['child_id']))
			{
				//module installation panel
				if($params['child_id']=='ModuleInstall')
				{
					$content = $ModC->find_new_modules();
					$this->Smarty->assign('content', $content);
					$output = $this->Smarty->fetch("mod_module_install.tpl");
				}
				//edit module panel
				elseif($params['child_id']=='EditModule')
				{
					$file_location = 'core';
					if(isset($params['mod_id']))
					{
						$file_location = $params['mod_id'];
					}

					$settings = $this->SC->list_settings($file_location);

					$this->Smarty->assign('file_location', $file_location);
					$this->Smarty->assign('settings', $settings);
					$output = $this->Smarty->fetch("mod_settings_admin.tpl");
				}
			}
			else
			{
				$offset = 0;
				if(isset( $params['OFFSET']))
				{
					$offset = $params['OFFSET'];
				}
				$order_by = 'MODULE_NAME ASC';
				if(isset( $params['ORDER_BY']))
				{
					$order_by = $params['ORDER_BY'];
				}
				$content = $ModC->list_modules($this->SC->get_setting('db_limit'), $offset, $order_by);
				$this->Smarty->assign('content', $content);
				$output = $this->Smarty->fetch('mod_module_admin.tpl');
			};
		}

		//WIDGET ADMIN MODULE
		elseif($params['module_id'] == 'WidgetAdmin')
		{
			$inactive = $this->WC->list_inactive_widgets();
			$active = $this->WC->list_active_widgets();
			$this->Smarty->assign('active', $active);
			$this->Smarty->assign('inactive', $inactive);
			$output = $this->Smarty->fetch('mod_widget_admin.tpl');
		}

		//THEME ADMIN MODULE
		elseif($params['module_id'] == 'ThemeAdmin')
		{
            $active_only = false;
			require_once(CONTROLS .'/theme_control.php');
			$TC = new Theme_Control($this->MC, $this->SC);
			$themes = $TC->list_all_themes($active_only);
			$this->Smarty->assign('themes', $themes);
			$output = $this->Smarty->fetch('mod_theme_admin.tpl');
		}

		//USER SETTINGS MODULE
		elseif($params['module_id'] == 'UserSettings')
		{
            if( !isset($params['child_id']) or ($params['child_id'] == '') )
			{
				$params['child_id'] = 'none';
			}

			//theme selector panel
			if($params['child_id']=='ThemeSelector')
			{
				$active_only = true;
				require_once(CONTROLS .'/theme_control.php');
				$TC = new Theme_Control($this->MC, $this->SC);
				$themes = $TC->list_all_themes($active_only);
				$this->Smarty->assign('themes', $themes);
				$output = $this->Smarty->fetch('mod_theme_admin.tpl');
			}
			//account edit panel
			elseif($params['child_id'] == 'EditAccount')
			{

	            require_once(CONTROLS .'/user_control.php');
				$UC = new User_Control($this->DC, $this->MC);
				$user = $UC->get_user($params['USER_ID']);
				$this->Smarty->assign('user', $user[0]);
				$output = $this->Smarty->fetch('mod_user_account.tpl');
			}
			//password change panel
			if($params['child_id']=='ChangePassword')
			{
				$active_only = true;
				require_once(CONTROLS .'/theme_control.php');
				$TC = new Theme_Control($this->MC, $this->SC);
				$themes = $TC->list_all_themes($active_only);
				$this->Smarty->assign('themes', $themes);
				$output = $this->Smarty->fetch('mod_user_password.tpl');
			}
			//user settings panel
			elseif($params['child_id']=='none')
			{
				$output = $this->Smarty->fetch("mod_user_settings.tpl");
			}

		}

		//USER ADMIN MODULE
		elseif($params['module_id'] == 'UserAdmin')
		{
			require_once(CONTROLS .'/user_control.php');
			$UC = new User_Control($this->DC, $this->MC);

			if( !isset($params['child_id']) or ($params['child_id'] == '') )
			{
				$params['child_id'] = 'none';
			}

			//edit user panel
			if($params['child_id']=='EditAccount')
			{
				$user = $UC->get_user($params['USER_ID']);
				$this->Smarty->assign('user', $user[0]);
				$output = $this->Smarty->fetch('mod_user_account.tpl');
			}
			//user list panel
			elseif($params['child_id']=='none')
			{
				$offset = 0;
				if(isset( $params['OFFSET']))
				{
					$offset = $params['OFFSET'];
				}
				$order_by = 'USER_ID ASC';
				if(isset( $params['ORDER_BY']))
				{
					$order_by = $params['ORDER_BY'];
				}
				$content = $UC->list_users($this->SC->get_setting('db_limit'), $offset, $order_by);
				$this->Smarty->assign('content', $content);
				$output = $this->Smarty->fetch('mod_user_admin.tpl');
			}
		}

		//ACCOUNT CREATION MODULE
		elseif($params['module_id'] == 'CreateAccount')
		{
			$output = $this->Smarty->fetch('mod_user_account_creation.tpl');
		}

		//LOGIN MODULE
		elseif($params['module_id'] == 'SignInPanel')
		{
			$output = $this->Smarty->fetch('mod_login.tpl');
		}

		//SETTINGS ADMIN MODULE
		elseif($params['module_id'] == 'SettingsAdmin')
		{
			$file_location = 'core';
			if(isset($params['file_location']))
			{
				$file_location = $params['file_location'];
			}
			$settings = $this->SC->get_settings($file_location);
            $this->Smarty->assign('file_location', $file_location);
			$this->Smarty->assign('settings', $settings);
			$output = $this->Smarty->fetch("mod_settings_admin.tpl");
		}

		//MODULE DOESNT EXIST
		else
		{
			$output = '<div style="text-align:left;">'.$breadcrumbs.'</div><div style="text-align:center;width:800px;height:400px;">ERROR: The Core module you are calling does not appear to exist</div>';
		}

		$this->output2display = $output;
	}

	/*******************************************************
	********************************************************/
	public function activate_module($params=array())
	{
		$this->admin_check();

		require_once(CONTROLS .'/module_control.php');
		$ModC = new Module_Control($this->DC, $this->MC, $this->SC);
		$output = $ModC->activate_module($params['module_id']);
		die($output);
	}

	/*******************************************************
	********************************************************/
	public function deactivate_module($params=array())
	{
		$this->admin_check();

		require_once(CONTROLS .'/module_control.php');
		$ModC = new Module_Control($this->DC, $this->MC, $this->SC);
		$output = $ModC->deactivate_module($params['module_id']);
		die($output);
	}

	/*******************************************************
	********************************************************/
	public function install_module($params=array())
	{
		$this->admin_check();

		require( CONTROLS . '/module_control.php' );
		$Module_Control = new Module_Control($this->DC, $this->MC, $this->SC);
	 	$output = $Module_Control->module_installation($params);
	 	die($output);
	}

	/**
	* <p>Uninstalls a module by removing its tables (if applicable) and removing it from the module table</p>
	*
	* @access	public
	* @author	Brian Cook < hide@address.com >
	* @params	$params['MODULE_ID'] the ID of the module
	* @return	none
	*/
	public function uninstall_module($params=array())
	{
		$this->admin_check();
		unset($params['f']);
		require( CONTROLS . '/module_control.php' );
		$Module_Control = new Module_Control($this->DC, $this->MC, $this->SC);
	 	$output = $Module_Control->module_uninstallation($params['module_id']);
	 	die($output);
	}

	/*******************************************************
	********************************************************/
	public function get_module_breadcrumbs($params)
	{
		return $this->MC->get_breadcrumbs('launchModule',$params);
	}

	/*******************************************************
	* <p>Checks to see if a module is active</p>
	*
	* @access	public
	* @author	Brian Cook < hide@address.com >
	* @param	$params['module_id'] the id of the module
	* @param	$params['version'] the version of the module you are checking
	* @return	boolean
	********************************************************/
	public function is_module_active($params=array())
	{
		//rip params
		$module_id = $params['module_id'];
		$version   = $params['version'];

		//create objects
		require_once( CONTROLS . '/module_control.php' );
		$Module_Control = new Module_Control($this->DC, $this->MC, $this->SC);

		//do function calls
		if(($Module_Control->module_is_installed( $module_id ))
		and($Module_Control->module_is_activated( $module_id ))
		and($Module_Control->get_module_version( $module_id ) == $version))
		{
		 	return true;
		}
		return false;
	}

/////////////////////////////
///////     USERS     ///////
/////////////////////////////

	/**
	* Logs a user in to the web site
	*
	* @access	public
	* @author	Chris Heidt < hide@address.com >
	* @param	$params['username'] the user name
	* @param	$params['password'] the user password
	* @return	none
	*/
	public function login_user($params=array())
	{
		require_once(CONTROLS .'/user_control.php');
		$UC = new User_Control($this->DC, $this->MC);
		$login_response = $UC->login_user($params['username'],$params['password']);
        if($login_response['error_count'] == 0)
		{
			exit("{success:true}");
		}
		else
		{
			$exception = explode(':',$login_response['message']);
			exit("{success:false, error:{ name:'$exception[0]',description:'$exception[1]'} }");
		}
         
		/*
		if($login_response['error_count'] == 0) $params['module_id'] = 'Home';
        else $params['MESSAGE'] = $this->get_styled_message($login_response['message'], $login_response['error_count']);
        $this->launch_core_module($params);
        */
	}

	/**
	* Logs the user out of the web site
	*
	* @access	public
	* @author	Chris Heidt < hide@address.com >
	* @param	none [see documentation about empty $params arrays]
	* @return	none
	*/
	public function logout_user($params=array())
	{
		require_once(CONTROLS .'/user_control.php');
		$UC = new User_Control($this->DC, $this->MC);
		$UC->logout_user();
		$this->get_widgets();
	}

	/**
	* Changes information about the user
	*
	* @access	public
	* @author	Chris Heidt < hide@address.com >
	* @param	$params['*'] the following fields in the user database can be altered with this function:
	*			FIRST_NAME, MIDDLE_NAME, LAST_NAME, NAME_PREFIX, DESCRIPTION
	* @param	$params['USER_ID'] the id of the user being updated
	* @return	none
	*/
	public function update_user($params=array())
	{
		require_once(CONTROLS .'/user_control.php');
		$UC = new User_Control($this->DC, $this->MC);
		$output = $UC->update_user($params);
        $this->Smarty->assign('MESSAGE', $this->get_styled_message($output['message'], $output['error_count']));
		$this->launch_core_module($params);
	}

	/**
	* Adds a new user account to the database
	*
	* @access	public
	* @author	Chris Heidt < hide@address.com >
	* @param	$params['*'] all information about the user. This includes: USER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME,
	* 			NAME_PREFIX, DESCRIPTION, PASSWORD_TEXT, PASSWORD_SALT,
	* @return	none
	*/
	public function create_user_account($params=array())
	{
		require_once(CONTROLS .'/user_control.php');
		$UC = new User_Control($this->DC, $this->MC);
		//$params['ACCOUNT_ACTIVE'] = $this->SC->get_setting('account_auto_activate');
		$params['PASSWORD_SALT'] = $this->SC->get_setting('password_salt');
        $params['account_auto_activate'] = $this->SC->get_setting('account_auto_activate', 'core');
        $params['url'] = $this->SC->get_setting('site_url', 'core');
        $params['smtp_server'] = $this->SC->get_setting('smtp_server', 'core');
        $params['THEME'] = $this->SC->get_setting('current_theme', 'core');
		$output = $UC->insert_user($params);

        $this->Smarty->assign('message', $this->get_styled_message($output['message'], $output['error_count']));
        if($output['error_count'] > 0)
        {
			$params['module_id'] = 'CreateAccount';
        }
        
        

        $this->launch_core_module($params);
	}

	/**
	* Removes a user account from the database
	*
	* @access	public
	* @author	Chris Heidt < hide@address.com >
	* @param	$params['USER_ID'] the user id to delete
	* @return	none
	*/
	public function delete_user_account($params=array())
	{
		$this->admin_check();

		require_once(CONTROLS .'/user_control.php');
		$UC = new User_Control($this->DC, $this->MC);
		$bool = $UC->delete_user($params['USER_ID']);
		if($bool)
		{
			exit("{success:true}");
		}
		else
		{
			$exception = $this->MC->get_message('user_delete_failed','core');
			exit("{success:false, error:{ name:'Deletion Error',description:'$exception'} }");
		}
	}

	/**
	* Sets a user account to active
	*
	* @access	public
	* @author	Chris Heidt < hide@address.com >
	* @param	$params['USER_ID'] the user id to activate
	* @return	none
	*/
	public function activate_user_account($params=array())
	{
		$this->admin_check();

		require_once(CONTROLS .'/user_control.php');
		$UC = new User_Control($this->DC, $this->MC);
		$bool = $UC->activate_user($params['USER_ID']);
		if($bool)
		{
			exit("{success:true}");
		}
		else
		{
			$exception = $params['USER_ID'] .' '. $this->MC->get_message('user_activate_failed','core');
			exit("{success:false, error:{ name:'Activation Error',description:'$exception'} }");
		}
	}

	/**
	* Sets a user account to active
	*
	* @access	public
	* @author	Chris Heidt < hide@address.com >
	* @param	$params['USER_ID'] the user id to activate
	* @return	none
	*/
    public function email_activate_user($params=array())
    {
        require_once(CONTROLS .'/user_control.php');
		$UC = new User_Control($this->DC, $this->MC);
        $output = $UC->email_activate_user($params);
        $message = $this->get_styled_message($output, 0);
		$this->get_widgets();
		$this->launch_core_module( array('module_id' => 'Home', 'MESSAGE'=>$message) );
		$this->Smarty->assign('theme_body', '../../themes/'.$this->get_theme().'/body.tpl');
		$this->Smarty->assign('module_output', $this->output2display);
		$this->Smarty->display('core.tpl');
		die();
    }

	/**
	* Sets a user account to inactive
	*
	* @access	public
	* @author	Chris Heidt < hide@address.com >
	* @param	$params['USER_ID'] the user id to deactivate
	* @return	none
	*/
	public function deactivate_user_account($params=array())
	{
		$this->admin_check();

		require_once(CONTROLS .'/user_control.php');
		$UC = new User_Control($this->DC, $this->MC);
		$bool = $UC->deactivate_user($params['USER_ID']);
		if($bool)
		{
			exit("{success:true}");
		}
		else
		{
			$exception = $params['USER_ID'] .' '. $this->MC->get_message('user_deactivate_failed','core');
			exit("{success:false, error:{ name:'Deactivation Error',description:'$exception'} }");
		}
	}

    public function change_user_password($params=array())
	{
		require_once(CONTROLS .'/user_control.php');
		$UC = new User_Control($this->DC, $this->MC);
		$params['PASSWORD_SALT'] = $this->SC->get_setting('password_salt', 'core');
        $params['USER_ID'] = $_SESSION['username'];
        $output = $UC->change_user_password($params);
        $params['module_id'] = 'UserSettings';
        if($output['error_count'] > 0)
        {
            $params['child_id'] = 'ChangePassword';
        }
        $this->Smarty->assign('message', $this->get_styled_message($output['message'], $output['error_count']));
        $this->launch_core_module($params);
	}

/////////////////////////////
///////    THEMES     ///////
/////////////////////////////

	/*******************************************************
	********************************************************/
	public function change_theme($params)
	{
		$theme_id = $params['default_theme'];
		require_once(CONTROLS .'/theme_control.php');
		$TC = new Theme_Control($this->MC, $this->SC);
		$results = $TC->change_current_theme($theme_id, $params, $this->DC);
        $params['MESSAGE'] = $this->get_styled_message($results['message'], $results['error_count']);
        $this->Smarty->assign('theme_body', '../../themes/'.$theme_id.'/body.tpl');
        $this->launch_core_module($params);
	}

    public function activate_theme($params)
    {
        $this->admin_check();

		$theme_id = $params['theme_id'];
		require_once(CONTROLS .'/theme_control.php');
		$TC = new Theme_Control($this->MC, $this->SC);
        $this->output2display = $TC->activate_theme($theme_id);
    }

    public function deactivate_theme($params)
    {
        $this->admin_check();

		$theme_id = $params['theme_id'];
		require_once(CONTROLS .'/theme_control.php');
		$TC = new Theme_Control($this->MC, $this->SC);
        $this->output2display = $TC->deactivate_theme($theme_id);
    }

    public function is_theme_active($params)
    {
        $theme_id = $params['theme_id'];
		require_once(CONTROLS .'/theme_control.php');
		$TC = new Theme_Control($this->MC, $this->SC);
		return $TC->is_theme_active($theme_id);
    }

    public function is_current_theme($params)
    {
        $theme_id = $params['theme_id'];
		require_once(CONTROLS .'/theme_control.php');
		$TC = new Theme_Control($this->MC, $this->SC);
        return $TC->is_current_theme($theme_id);
    }

    public function get_theme()
    {
        if((isset($_SESSION['username']) and ($_SESSION['username'] != '')) and ($_SESSION['is_admin'] != 1))
        {
            return $_SESSION['theme'];
        }

        return trim($this->SC->get_setting('current_theme'));
    }

/////////////////////////////
///////   Settings    ///////
/////////////////////////////


	/*******************************************************
	********************************************************/
	public function edit_settings($params)
	{
		$this->admin_check();

		$file_location = $params['file_location'];
		unset($params['file_location'], $params['f']);
        if(isset($params['ajax'])) unset($params['ajax']);

		$failures = array();
        $error_count = 0;
		$message = '';

		foreach($params as $key => $val)
		{
			if(($key != 'save') and ($key != 'module_id'))
            {
                $status = $this->SC->set_setting($key, $val, $file_location);

                if($status === false)
                {
                    array_push($failures, $key);
                    $error_count++;
                }
            }
		}

		if($error_count > 0)
		{
		 	$message .= $this->MC->get_message('setting_update_failed', 'core');
            foreach($failures as $wtfarray)
            {
                $message .= $wtfarray . '<br />';
            }
		}
        else
        {
            $message .= $this->MC->get_message('setting_update_successful', 'core');
        }

		$this->Smarty->assign('message', $this->get_styled_message($message, $error_count));
        $this->launch_core_module($params);
	}

	/*******************************************************
	********************************************************/
	public function upload_zip($params)
	{
        $this->admin_check();

		$message = '';
        $error_count = 0;
		if(stristr($_FILES['upload_module_path']['type'], 'zip') !== FALSE)
		{
            $Zip = new ZipArchive(); //need to include php_zip.dll in php.ini.
            $target_dir = MODULES . '/';
            if ($Zip->open($_FILES['upload_module_path']['tmp_name']) === TRUE) {
                try {
                    $Zip->extractTo($target_dir);
                    $Zip->close();
                    $message .= $this->MC->get_message("file_upload_success", "core");
                } catch (Exception $e) {
                   $message .= $this->MC->get_message("caught_exception", "core");
                   $message .= $e->getMessage();
                   $error_count++;
                }
            }
		} else {
            $message .=  $this->MC->get_message("file_not_found_zip", "core");
            $error_count++;
        }
        $this->Smarty->assign('message', $this->get_styled_message($message, $error_count));
        $this->launch_core_module($params);
	}

	/*******************************************************
	********************************************************/
	public function upload_theme($params)
	{
        $this->admin_check();

		$message = '';
        $error_count = 0;
		if(stristr($_FILES['upload_theme_path']['type'], 'zip') !== FALSE)
		{
            $Zip = new ZipArchive(); //need to include php_zip.dll in php.ini.
            $target_dir = THEMES . '/';
            if ($Zip->open($_FILES['upload_theme_path']['tmp_name']) === TRUE) {
                try {
                    $Zip->extractTo($target_dir);
                    $Zip->close();
                    $message .= $this->MC->get_message("file_upload_success", "core");
                } catch (Exception $e) {
                   $message .= $this->MC->get_message("caught_exception", "core");
                   $message .= $e->getMessage();
                   $error_count++;
                }
            }
		} else {
            $message .=  $this->MC->get_message("file_not_found_zip", "core");
            $error_count++;
        }
        $this->Smarty->assign('message', $this->get_styled_message($message, $error_count));
        $this->launch_core_module($params);
	}
}//end class
?>
Return current item: EXtensible Production Suite (XPS)