HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/spire.komma-mediadesign.nl/wwwroot/kms/client/controllers/c_vacancy.php
<?php

/*
	
	c_news.php // Controller
	
	First checks if any actions need to be and then guides user to the right page. 

*/


require_once DOCUMENT_ROOT.'client/models/m_vacancy.php';

require_once DOCUMENT_ROOT.'app/models/m_display.php';
require_once DOCUMENT_ROOT.'app/models/m_sorter.php';
require_once DOCUMENT_ROOT.'app/models/images/m_imageHandler.php';

/** 
*
* Check if the "sub" GET variable is set
*/
if(defined('URL_SUB')) $sub = URL_SUB;
if(defined('URL_SUB2')) $sub2 = URL_SUB2;


/** 
*
* Set a few hardcoded variables for this page
*/
$linkname = 'vacatures';
$pageId = 4;
$this->setdata('page_label', $this->lang['vacancies'], TRUE);


/**
*
* Image dimensions are set by an array( largeWidth(int), largeHeight(int), thumbwidth(int), $thumbHeight(int), kmsThumb(int), kmsThumb(int));
* A standard is set, but for every page we can set a different array.
*/
$std = array('lw' => 600, 'lh' => null, 'tw' => 300, 'th' => 200, 'mw' => 60, 'mh' => 60);
switch($pageId)
{
	default: 
		$imgDim = $std;
}

/**
*
* Add objects
*/
$Vacancypage = new Vacancypage();
$ImageHandler = new ImageHandler($pageId,$imgDim);
$ImageHandler->setMaxImages(1);
$ImageStorage = new ImageStorage($pageId);
/***********************************************************************************/

/*
	 Check if any actions are needed
*/


/*
	 ADD / EDIT
*/

/**
*
* If user hits the "save" button. We call the Vacancypage::store function to validate and save the values.
* When this method returns false, we check what went wrong and display this errors to the user.
* When the method returns true, storage is succes so redirect to "dashboard".
*/
if(isset($_POST['sbm_save_new']))
{
	if($Vacancypage->store())
	{
		$this->redirect(LANG_ROOT.$linkname.'/');
	}
	else
	{
		foreach($Vacancypage->getErrors() as $error)
		{
			$this->setAlert($error,'error');
		}
		$this->redirect(LANG_ROOT.$linkname.'/nieuw-item/');
	}
}

/**
*
* If the user hits the "save" button in the "edit-form", or the image "upload" is submitted, two things can happen:
* We need to save the item, or we need to add images
* First save all data which was already filled, so the user does not have to refill these.
* If addImages returns false, we dont have to add images, so we need to update the item.
* We also need to make sure that images that are no longer in the session, should be removed from the database and the server.
* If item stored we return to the "dashboard", if images added we return to the "edit-form".
*/
else if(isset($_POST['sbm_save_edit']))
{
	if(isset($sub2))
	{
		$id = $sub2;
		if($Vacancypage->store($id))
		{
			$ImageHandler->removeStoredImages($id);
			if($ImageStorage->store($id, $_SESSION[$linkname . '_images_to_store']))
			{
				unset($_SESSION[$linkname . '_images_to_store']);
			}
	
			$this->redirect(LANG_ROOT.$linkname.'/');
		}
		else
		{
			foreach($Vacancypage->getErrors() as $error)
			{
				$this->setAlert($error,'error');
			}
			$this->redirect(LANG_ROOT.$linkname.'/wijzig-item/'.$id.'/');
		}
		
	}
}

/**
*
* Validate images when the upload button is hit.
* 
*/
else if( isset($_FILES['images']) )
{
	
	if( ! $ImageHandler->addImages())
	{
		// error handling ?
	}
	$this->returnToSessionUrl();
}

		
/*
	 REMOVE TO TRASH
*/

/**
*
* If the user hits the submit button to delete items, first thing we need to do is ask the user if he is sure about this.
* We grap an data array through the MealCategory::Get method.
* A string of list items is created and stored in the Template::data property.
* Also an array ids is stored.
*/
else if(isset($_POST['prepare_delete_items']))
{
	if(isset($_POST['selected']))
	{
		if($data = $Vacancypage->get($_POST['selected']))
		{
			$Display = new Display();
			list($output, $ids) = $Display->createList($data, FALSE);
			
			$this->setData('item_list', $output, TRUE);
			$this->setData('list_ids', $ids, TRUE);	
		}
	}
	else
	{
		$this->setAlert($this->lang['general_nothing_selected'],'warning');
		$this->redirect(LANG_ROOT.$linkname.'/');
	}
}

/**
* 
* If the user hits the button to confirm he wants to delete something, we add a new Trashcan object.
*/
else if(isset($_POST['sbm_delete_items']))
{
	$ids = explode(',',$_POST['ids']);
	
	$Trashcan = new Trashcan();
	$Trashcan->setPageInfo(array('id'=>$pageId,'linkname'=>'categorien','label'=>'Categori&euml;n'));
	$Trashcan->insert($ids);
	
	$this->redirect(LANG_ROOT.'/'.$linkname);
}

/*
	 CHANGE ORDER OF ITEMS
*/

/**
*
* When the user hits the order button in the order (items) form. An array of ids is grapped from the comma-seperated string in the order form.
* A new sorter object is created, this updates the order. We redirect back to the "dashboard".
*/
else if(isset($_POST['sbm_order_items']))
{
	$ids = explode(',',$_POST['sort_order']);
	$tn = $Vacancypage->getTableName();
	
	$Sorter = new Sorter($pageId, $tn, 'itemOrder');
	$Sorter->update($ids);
	
	$this->redirect(LANG_ROOT.$linkname.'/');
}

/*
	 ADD CROPPED IMAGES
*/

/**
*
* If the user hits the button submit after cropping his images. The imagesHandler calles the method ImageHandler::addCroppedImages.
* The images will be added to the current session "images_to_store".
*/
else if(isset($_POST['sbm_crop']))
{
	$ImageHandler->addCroppedImages();
	$this->returnToSessionUrl();
}

/**
*	
*	Check if there are any actions needed when a subpage is found
*/
else if(isset($sub))
{
	switch($sub)
	{
		/**
		*
		* Show list of images in session
		*/
		case 'nieuw-item':
			$_SESSION['return_to']['url'] = 'nieuw-item';
			$ImageHandler->createList();
		break;	
		/**
		*
		* When we are going to edit an item. The storage session needs to be filled with data from the database.
		*/
		case 'wijzig-item':
			$_SESSION['return_to']['url'] = 'wijzig-item';
			$_SESSION['return_to']['id'] = $sub2;
			
			if(isset($sub2)) 
			{
				$Vacancypage->setStorageData($sub2);
				
				// add stored images to session (only once)
				if(!isset($_SESSION['stored_added']))
				{	
					if($arr = $ImageStorage->get('itemId',$sub2))
					{	
						$session = $_SESSION[$linkname . '_images_to_store'];
						foreach($arr as $data)
						{
							$session->add($data);				
						}
						$_SESSION['stored_added'] = TRUE;
					}
				}
			}
			$ImageHandler->createList();
		break;	
		
		/**
		*
		* This is the page where the user is asked to confirm his wish to delete (one) item.
		* In order to show what item he clicked on, we get a the info by the id
		*/
		case 'verwijder-item':
			if($item = $Vacancypage->get(array($sub2)))
			{
				$Display = new Display();
				list($output, $ids) = $Display->createList($item, FALSE);
				$this->setData('item_list', $output, TRUE);
				$this->setData('list_ids', $ids, TRUE);	
			}
			else
			{
				$this->redirect(LANG_ROOT.$linkname.'/');
			}
		break;
		
		/**
		*
		* This is the page where we change the order of items.
		* First we get options to pass into het Multipage::get method. (The zero stands for no page 'LIMIT', so you get a list of all items)
		* Then add a new sorter object and retrieve a list.
		*/
		case 'wijzig-volgorde':
			
			$Vacancypage->setMaxItems(0);
			$items = $Vacancypage->get();
			$sorter = new Sorter($pageId);
			$sorter->createList($items);
		break;
		
		/**
		*
		* This happens when the user clicks on the X to delete an image from the session.
		* The session key is passed through $sub2. Redirect back to the page where the user came from. (for example "add-form" or "edit-form").
		* Check this width the return_to session.
		*/
		case 'remove-image':	
			echo $sub2;
			if(isset($sub2) && is_numeric($sub2))
			{
				$_SESSION[$linkname . '_images_to_store']->remove($sub2);
			}
			$this->returnToSessionUrl();
		break;
	
		/**
		*
		* When a user is about to crop some images. We have to set the cropdata first.
		*/
		case 'crop':
			foreach($_SESSION['images_to_crop'] as $key => $value)
			{
				$this->setdata('minW'.$key,$imgDim['tw']);
				$this->setdata('minH'.$key,$imgDim['th']);
				$this->setdata('maxW'.$key,0);
				$this->setdata('maxH'.$key,0);
			}
		break;	
	}
}

/**
*	
*	Code below is used for the dashboard of the news page
*	A string of list items is created and stored in the Template::data property.
*	Also an array ids is stored.
*/
else
{
	$data = $Vacancypage->get();
	
	$Display = new Display();
	list($output, $ids) = $Display->createList($data);
	
	$this->setData('item_list', $output, TRUE);
	$this->setData('list_ids', $ids, TRUE);
	
	$Vacancypage->clean();
	unset($_SESSION['stored_added']);
}


/***********************************************************************************/

/*
	 Guide user to page
*/

/**
*	
*	If a subpage is found, switch this and guide the user to the right page
*	When no page found, header a 404-error and display a nice message to the user.
*/
if(isset($sub))
{
	switch($sub)
	{
		case 'nieuw-item':
			// form add item
			$this->load(DOCUMENT_ROOT.'client/views/vacancy/v_vacancy_addedit.php', $this->lang['new_vacancy'].' | '.$this->lang['vacancies'].' | '.SITE_NAME);
		break;
		case 'wijzig-item':
			// form edit item
			$this->load(DOCUMENT_ROOT.'client/views/vacancy/v_vacancy_addedit.php', $this->lang['edit_vacancy'].' | '.$this->lang['vacancies'].' | '.SITE_NAME);
		break;
		case 'verwijder-items':
			// ask user confirmation (delete multiple items)
			$this->load(DOCUMENT_ROOT.'app/views/trashcan/v_kms_trashcan_delete.php', $this->lang['delete_vacancies'].' | '.$this->lang['vacancies'].' | '.SITE_NAME);
		break;
		case 'verwijder-item':
			// ask user confirmation (delete 1 item)
			$this->load('app/views/trashcan/v_kms_trashcan_delete.php', $this->lang['delete_vacancy'].' | '.$this->lang['vacancies'].' | '.SITE_NAME);
		break;
		case 'wijzig-volgorde':
			// sortable list
			$this->load('app/views/sortorder/v_kms_order_items.php', $this->lang['order_vacancies'].' | '.$this->lang['vacancies'].' | '.SITE_NAME);
		break;
		default:
			// 404
			$this->notFound();
	}
}
else{
	// dashboard
	$this->load('client/views/vacancy/v_vacancy_dashb.php', $this->lang['vacancies'].' | '.SITE_NAME);
}