Location: PHPKode > projects > EXtensible Production Suite (XPS) > xpsdev/core/controls/widget_control.php
<?php

/***********************************************************************************************************
*
* <p></p>
*
* @author heidtc < hide@address.com >
*
************************************************************************************************************/
Class Widget_Control
{
	private $Widget;
	private $DC;
	private $Message_Control;


	/***************************************************
	* <p>constructor for widget control.</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >, Travis Rennemann <hide@address.com>
	* @param	Object [$Database] The database object
	* @return	type description
	***************************************************/
	public function __construct($DC,$MC)
	{
		require_once( MODELS . '/widget.php');
		$this->Widget = new Widget;
		$this->DC = $DC;
		$this->Message_Control = $MC;
	}

	/**********************************************************************
	**********************************************************************/
	public function log_position_changes($params = array())
	{
        
		$message = $this->Message_Control->get_message('widget_update_complete','core'); //default update message; which is changed when an error is encountered.
		$query_params = split(':', $params['value']);
		$params['CONTAINER_ID'] = $query_params[0];
        //$params['USER_ID'] = $_SESSION['username'];
		unset($params['f'], $params['value']);
		$stack = 1;

        foreach (split(',', $query_params[1]) as $widget)
        {
            $params['STACK_ORDER'] = $stack;
            $params['WIDGET_ID'] = $widget;
            if(isset($_SESSION['username']) and ($_SESSION['is_admin'] != 1))
            {

				//See if this user already has preferences set for this widget.
                $rs = $this->DC->get_recordset('count_user_widget_pref','core', array('USER_ID' => $_SESSION['username'], 'WIDGET_ID' => $params['WIDGET_ID']));

  				$params['USER_ID'] = $_SESSION['username'];
				if($rs[0]['PREF_COUNT'] == 1)
                {
                    $bool = $this->DC->execute_sql('update_user_widget_pref','core',$params);
                }
                else
                {
					$bool = $this->DC->execute_sql('insert_user_widget_pref','core',$params);
                }
            }
            else //User is admin and admin sets the default widget positions.
            {
				$bool = $this->DC->execute_sql('set_position','core',$params);
            }

            $stack++;
            if($bool == false)
            {
                $message = $this->Message_Control->get_message('widget_update_failed','core');
				break;
            }
        }

		return $message;
	}

	/**********************************************************************
	* <p>Show all widgets, regardless of parent module
	*
	* @access   public
	* @author 	heidtc < hide@address.com >, Brian Cook < hide@address.com >, Travis Rennemann <hide@address.com>
	* @param	none
	* @return	none
	**********************************************************************/
	public function show_all_widgets($API, $params)
	{
		$template_dir = $API->Smarty->template_dir;
        $session_widgets = array();
        $user_widget_prefs = array();

        if(isset($_SESSION['username']) and ($_SESSION['is_admin'] != 1))
        {
			$params['USER_ID'] = $_SESSION['username'];
            $user_widget_prefs = $this->DC->get_recordset('get_user_widget_prefs','core', $params);
            
			foreach($user_widget_prefs as $user_widget_pref)
	        {
	            $params['MODULE_ID'] = $user_widget_pref['MODULE_ID'];
	            unset($params['USER_ID']);
				$parent_mod = $this->DC->get_recordset('module_information', 'core', $params);

				if($parent_mod[0]['IS_ACTIVE'] == 1)
	            {
					
					if($user_widget_pref['MODULE_ID'] == 'core')
		            {
		                require_once(WIDGETS. '/' . $user_widget_pref['URL']);
		            }
		            else
		            {
		                require_once(MODULES. '/' . $user_widget_pref['MODULE_ID'] .'/widgets/' . $user_widget_pref['URL']);
		            }
		
		            $Widget_Object = new $user_widget_pref['WIDGET_ID']($API, $params);
		            if($user_widget_pref['USER_CONTAINER_ID']) $user_widget_pref['CONTAINER_ID'] = $user_widget_pref['USER_CONTAINER_ID'];
		            
		            $session_widgets[$user_widget_pref['WIDGET_ID']] = array
		                                                ('name' => $user_widget_pref['WIDGET_NAME'],
									  					'container' => $user_widget_pref['CONTAINER_ID'],
														'content' => $Widget_Object->output );
		            $API->Smarty->template_dir = $template_dir;
		        }
	        }
        }
		else
		{
			$widgets = $this->list_widgets();
			foreach($widgets as $widget)
	        {
	            unset($params['f'], $params['value'], $params['widget_id']);
				
				$params['MODULE_ID'] = $widget['MODULE_ID'];

				$parent_mod = $this->DC->get_recordset('module_information', 'core', $params);

				if($parent_mod[0]['IS_ACTIVE'] == 1)
	            {
					if($widget['MODULE_ID'] == 'core')
		            {
		                require_once(WIDGETS. '/' . $widget['URL']);
		            }
		            else
		            {
		                require_once(MODULES. '/' . $widget['MODULE_ID'] .'/widgets/' . $widget['URL']);
		            }
		
		            $Widget_Object = new $widget['WIDGET_ID']($API, $params);
		            $session_widgets[$widget['WIDGET_ID']] = array
		                                                ('name' => $widget['WIDGET_NAME'],
									  					'container' => $widget['CONTAINER_ID'],
														'content' => $Widget_Object->output );
		            $API->Smarty->template_dir = $template_dir;
		        }
	        }
		}
	
        return $session_widgets;
	}

	/**********************************************************************
	* <p>list all active widgets, regardless of parent module</p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	array [$params] array of parameters
	* @return	recordset
	**********************************************************************/
	public function list_widgets($params = array())
	{
		return $this->DC->get_recordset('list_widgets');
	}

	/**********************************************************************
	* <p></p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	module_id
	* @return	recordset
	**********************************************************************/
	public function list_module_widgets($module_id)
	{
		$params = array();
		$params['MODULE_ID'] = $module_id;

		return $this->DC->get_recordset('list_module_widgets', 'core', $params);
	}

	/**********************************************************************
	* <p></p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	module_id
	* @return	bool
	**********************************************************************/
	public function deactivate_module_widgets($module_id)
	{
		$bool = true;
		$widget_list = '';
		$widgets = $this->list_module_widgets($module_id);

		if( count($widgets) > 0)
		{
			foreach($widgets as $widget)
			{
				$bool = $this->deactivate_widget($widget['WIDGET_ID']);

				if($bool)
				{
					$widget_list .= $widget['WIDGET_ID'] . ', ';
				}
			}
		}
		return $widget_list;
	}

	/**********************************************************************
	* <p></p>
	*
	* @access   public
	* @author 	heidtc < hide@address.com >
	* @param	module_id
	* @return	bool
	**********************************************************************/
	public function deactivate_widget($widget_id)
	{
		$params = array();
		$params['WIDGET_ID'] = $widget_id;
		$params['CONTAINER_ID'] = 'inactive_widget_container';

		$bool = $this->DC->execute_sql('deactivate_widget','core',$params);
		return $bool;
	}

}//end class
Return current item: EXtensible Production Suite (XPS)