/**
	 * Checks for OPT_DEL_ON_UNINSTALL -> removes option and all files and the last folder, if empty
	 */
   public function on_uninstall()
   {
	   woocommerce_email_attachments::$admin_message = 'Uninstallation successfull';
		
		$this->options = get_option(woocommerce_email_attachments::OPTIONNAME, array());
		
		//	already deleted on deactivation
		if(empty($this->options))
		{
			return;
		}
		
		//	fallback - Delete in any case to clean up database
		if(!isset($this->options[woocommerce_email_attachments::OPT_DEL_ON_UNINSTALL]) || 
				$this->options[woocommerce_email_attachments::OPT_DEL_ON_UNINSTALL])
		{
			$this->delete_files();
			delete_option(woocommerce_email_attachments::OPTIONNAME);
		}
   }
	/**
	 * Saves the options in own option entry
	 */
	protected function save_all_options()
	{
		$this->options[self::OPT_DEL_ON_DEACTIVATE] = isset($_REQUEST[self::OPT_DEL_ON_DEACTIVATE]);
		$this->options[self::OPT_DEL_ON_UNINSTALL] = isset($_REQUEST[self::OPT_DEL_ON_UNINSTALL]);
		
		$oldpath = $newpath = strtolower($this->options[self::OPT_UPLOAD_FOLDER]);
		if(isset($_REQUEST[self::OPT_UPLOAD_FOLDER]))
		{
			$newpath = trim(strtolower(stripslashes($_REQUEST[self::OPT_UPLOAD_FOLDER])));
			$newpath = str_replace('\\', '/', $newpath);
			if(strlen($newpath) == 0)
			{
				$newpath = $oldpath;
			}
			else
			{
				$newpath = trailingslashit($newpath);
			}
			if(strcasecmp ($oldpath, $newpath)!= 0)
			{
				$this->options[self::OPT_UPLOAD_FOLDER] = $this->move_uploadfolder($oldpath, $newpath);
			}
		}
		
		
		if(isset($_REQUEST[self::OPT_EMAIL_NOTIFICATION_HEADLINE]) && !empty($_REQUEST[self::OPT_EMAIL_NOTIFICATION_HEADLINE]))
		{
			$this->options[self::OPT_EMAIL_NOTIFICATION_HEADLINE] = trim($_REQUEST[self::OPT_EMAIL_NOTIFICATION_HEADLINE]);
		}
		else
			$this->options[self::OPT_EMAIL_NOTIFICATION_HEADLINE] = '';
		
		if(isset($_REQUEST[self::OPT_EMAIL_NOTIFICATION_TEXT]) && !empty($_REQUEST[self::OPT_EMAIL_NOTIFICATION_TEXT]))
		{
			$this->options[self::OPT_EMAIL_NOTIFICATION_TEXT] = trim($_REQUEST[self::OPT_EMAIL_NOTIFICATION_TEXT]);
		}
		else
			$this->options[self::OPT_EMAIL_NOTIFICATION_TEXT] = '';
		
		
		$this->options[self::OPT_ATT_NEW_ORDER] = $this->get_selected_files(self::OPT_ATT_NEW_ORDER);
		$this->options[self::OPT_ATT_PROCESSING] = $this->get_selected_files(self::OPT_ATT_PROCESSING);
		$this->options[self::OPT_ATT_COMPLETED] = $this->get_selected_files(self::OPT_ATT_COMPLETED);
		$this->options[self::OPT_ATT_INVOICE] = $this->get_selected_files(self::OPT_ATT_INVOICE);
		$this->options[self::OPT_ATT_NOTE] = $this->get_selected_files(self::OPT_ATT_NOTE);
		$this->options[self::OPT_ATT_LOW_STOCK] = $this->get_selected_files(self::OPT_ATT_LOW_STOCK);
		$this->options[self::OPT_ATT_NO_STOCK] = $this->get_selected_files(self::OPT_ATT_NO_STOCK);
		$this->options[self::OPT_ATT_BACKORDER] = $this->get_selected_files(self::OPT_ATT_BACKORDER);
		$this->options[self::OPT_ATT_NEW_ACCOUNT] = $this->get_selected_files(self::OPT_ATT_NEW_ACCOUNT);
		
		$this->options[self::OPT_HEAD_NEW_ORDER] = $this->get_emailaddress(self::OPT_HEAD_NEW_ORDER);
		$this->options[self::OPT_HEAD_PROCESSING] = $this->get_emailaddress(self::OPT_HEAD_PROCESSING);
		$this->options[self::OPT_HEAD_COMPLETED] = $this->get_emailaddress(self::OPT_HEAD_COMPLETED);
		$this->options[self::OPT_HEAD_INVOICE] = $this->get_emailaddress(self::OPT_HEAD_INVOICE);
		$this->options[self::OPT_HEAD_NOTE] = $this->get_emailaddress(self::OPT_HEAD_NOTE);
		$this->options[self::OPT_HEAD_LOW_STOCK] = $this->get_emailaddress(self::OPT_HEAD_LOW_STOCK);
		$this->options[self::OPT_HEAD_NO_STOCK] = $this->get_emailaddress(self::OPT_HEAD_NO_STOCK);
		$this->options[self::OPT_HEAD_BACKORDER] = $this->get_emailaddress(self::OPT_HEAD_BACKORDER);
		$this->options[self::OPT_HEAD_NEW_ACCOUNT] = $this->get_emailaddress(self::OPT_HEAD_NEW_ACCOUNT);
		
		
		update_option(self::OPTIONNAME, $this->options);
		
		self::$admin_message = 'Options saved';
	}
	    ( false !== strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) ) )
	{
		require_once $woocommerce_email_attachments_plugin_path.'v210/inoplugs_plupload/inoplugs_plupload.php';
	}
}

/**
 * load woocommerce_email_attachments class
 **/
if ( ! class_exists( 'woocommerce_email_attachments_activation' ) )
{
	require_once $woocommerce_email_attachments_plugin_path . 'v210/woocommerce_email_attachments_activation.php';
}

if ( ! class_exists( 'woocommerce_email_attachments' ) )
{
	require_once $woocommerce_email_attachments_plugin_path.'v210/woocommerce_email_attachments.php';
	
	global $woocommerce_email_attachments;
	$woocommerce_email_attachments = new woocommerce_email_attachments();
	
	add_action( 'admin_notices', array('woocommerce_email_attachments', 'show_admin_messages') );

	global $wc_email_att_skip_files, $wc_email_att_upload_basedir;
	
	woocommerce_email_attachments::$skip_files = $wc_email_att_skip_files;
	woocommerce_email_attachments::$plugin_url = $woocommerce_email_attachments_plugin_url;
}