public function widgetinstances_save(){
		$view = $this->getView();
		$request = $this->getPageRequest();

		if(!\Core\user()->checkAccess('p:/core/widgets/manage')){
			return View::ERROR_ACCESSDENIED;
		}

		if(!$request->isPost()){
			return View::ERROR_BADREQUEST;
		}

		$counter = 0;
		$changes = ['created' => 0, 'updated' => 0, 'deleted' => 0];

		$selected = $_POST['selected'];
		// For the incoming options, I want an explicit NULL if it's empty.
		$theme    = $_POST['theme'] == '' ? null : $_POST['theme'];
		$skin     = $_POST['skin'] == '' ? null : $_POST['skin']; $_POST['skin'];
		$template = $_POST['template'] == '' ? null : $_POST['template'];
		$baseurl  = $_POST['page_baseurl'] == '' ? null : $_POST['page_baseurl'];

		foreach($_POST['widgetarea'] as $id => $dat){

			// Merge in the global information for this request
			//$dat['theme']         = $theme;
			//$dat['skin']          = $skin;
			$dat['template']      = $template;
			$dat['page_baseurl']  = $baseurl;

			$dat['weight'] = ++$counter;
			$dat['access'] = $dat['widgetaccess'];

			$w = WidgetModel::Construct($dat['baseurl']);
			$dat['site'] = $w->get('site');

			if(strpos($id, 'new') !== false){
				$w = new WidgetInstanceModel();
				$w->setFromArray($dat);
				$w->save();
				$changes['created']++;
			}
			elseif(strpos($id, 'del-') !== false){
				$w = new WidgetInstanceModel(substr($id, 4));
				$w->delete();
				// Reset the counter back down one notch since this was a deletion request.
				--$counter;
				$changes['deleted']++;
			}
			else{
				$w = new WidgetInstanceModel($id);
				$w->setFromArray($dat);
				if($w->save()) $changes['updated']++;
			}
		} // foreach($_POST['widgetarea'] as $id => $dat)

		// Display some human friendly status message.
		if($changes['created'] || $changes['updated'] || $changes['deleted']){
			$changetext = [];

			if($changes['created'] == 1) $changetext[] = 'One widget added';
			elseif($changes['created'] > 1) $changetext[] = $changes['created'] . ' widgets added';

			if($changes['updated'] == 1) $changetext[] = 'One widget updated';
			elseif($changes['updated'] > 1) $changetext[] = $changes['updated'] . ' widgets updated';

			if($changes['deleted'] == 1) $changetext[] = 'One widget deleted';
			elseif($changes['deleted'] > 1) $changetext[] = $changes['deleted'] . ' widgets deleted';

			\Core\set_message(implode('<br/>', $changetext), 'success');
		}
		else{
			\Core\set_message('t:MESSAGE_INFO_NO_CHANGES_PERFORMED');
		}

		if($baseurl){
			\Core\redirect($baseurl);
		}
		else{
			\Core\redirect('/admin/widgets?selected=' . $selected);
		}

	}
	/**
	 * Controller view to install 1 widget into one selected area, be that area a skin, or page template.
	 *
	 * @return int
	 */
	public function instance_install(){
		$view = $this->getView();
		$request = $this->getPageRequest();

		if(!\Core\user()->checkAccess('p:/core/widgets/manage')){
			return View::ERROR_ACCESSDENIED;
		}

		if(!$request->isPost()){
			return View::ERROR_BADREQUEST;
		}

		// For the incoming options, I want an explicit NULL if it's empty.
		$template       = (isset($_POST['template']) && $_POST['template'] != '') ? $_POST['template'] : null;
		$page_baseurl   = (isset($_POST['page_baseurl']) && $_POST['page_baseurl'] != '') ? $_POST['page_baseurl'] : null;
		$widget_baseurl = (isset($_POST['widget_baseurl']) && $_POST['widget_baseurl'] != '') ? $_POST['widget_baseurl'] : null;
		$widgetarea     = (isset($_POST['area']) && $_POST['area'] != '') ? $_POST['area'] : null;

		$wm = WidgetModel::Construct($widget_baseurl);
		$dat['site']         = $wm->get('site');
		$dat['baseurl']      = $widget_baseurl;
		$dat['template']     = $template;
		$dat['page_baseurl'] = $page_baseurl;
		$dat['widgetarea']   = $widgetarea;

		if($template){
			$counter = WidgetInstanceModel::Count(['template = ' . $template, 'widgetarea = ' . $widgetarea]);
			$w = new WidgetInstanceModel();
			$w->setFromArray($dat);
			$w->set('weight', $counter + 1);
			$w->save();

			\Core\set_message('Installed widget into requested template', 'success');
		}
		elseif($page_baseurl){
			$counter = WidgetInstanceModel::Count(['page_baseurl = ' . $page_baseurl, 'widgetarea = ' . $widgetarea]);
			$w = new WidgetInstanceModel();
			$w->setFromArray($dat);
			$w->set('weight', $counter + 1);
			$w->save();

			\Core\set_message('Installed widget into requested page', 'success');
		}
		else{
			\Core\set_message('Unknown request', 'error');
		}

		if($page_baseurl){
			\Core\redirect($page_baseurl);
		}
		else{
			\Core\redirect('/widget/admin?template=' . $template);
		}
	}