Beispiel #1
0
	/**
	* Initialises this method for exporting
	*
	* @param ISC_ADMIN_EXPORTOPTIONS The options to export with
	*/
	public function Init(ISC_ADMIN_EXPORTOPTIONS $options)
	{
		$filetype = $options->getFileType();

		// initialise the file type
		$filetype->Init($this, $options->getTemplateId(), $options->getWhere(), $options->getHaving());

		// set the type name
		$details = $filetype->GetTypeDetails();
		$name = $details['name'];
		if (substr($name, -1, 1) == "s") {
			$name = substr($name, 0, -1);
		}
		$this->type_name = $name;

		$this->filetype = $filetype;

		// load settings for this method
		$settings = $this->GetSettings($options->getTemplateId());
		foreach ($settings as $var => $setting) {
			$this->settings[$var] = $setting['value'];
		}

		$this->className = 'exporttemplate';
		$this->exportName = $details['title'];
		$GLOBALS['ExportName'] = $details['title'];
		$GLOBALS['ExportGenerate'] = GetLang('AjaxExportLink', array('title' => isc_strtolower($details['title']), 'type' => $this->method_name));
		$GLOBALS['ExportIntro'] = GetLang('AjaxExportIntro');
	}
Beispiel #2
0
	private function RunExport()
	{
		try {
			// check for a selected template
			if (empty($_REQUEST["template"]) && !$this->filetype->ignore) {
				throw new Exception(GetLang("NoTemplateSelected"));
			}

			if (!isset($_REQUEST['format'])) {
				throw new Exception(GetLang("NoMethodSelected"));
			}

			$details = $this->filetype->GetTypeDetails();

			$templateid = $_REQUEST["template"];

			if (!$this->filetype->ignore) {
				// check template exists
				$template = $this->templates->GetTemplate($templateid);

				// check the file type is available for this template
				if (!in_array($this->type, explode(",", $template['usedtypes']))) {
					throw new Exception(sprintf(GetLang("TypeNotAvailable"), $this->type));
				}

				$templateName = $template['exporttemplatename'];
			}
			else {
				$templateName = $details['title'];
			}

			$where = "";
			$having = "";

			// get the custom search fields
			if (isset($_REQUEST['ids'])) {
				$ids = explode(',', $_REQUEST['ids']);
				$ids = implode(', ', array_map(array($GLOBALS['ISC_CLASS_DB'], "Quote"), $ids));

				$where = $details['idfield'] . " IN (" . $_REQUEST["ids"] . ")";
			}
			elseif (isset($_REQUEST['params'])) {
				$params = $this->GetParams($_REQUEST['params']);
				$ret = $this->filetype->BuildWhereFromFields($params);

				if (is_array($ret)) {
					$where = $ret['where'];
					if (isset($ret['having'])) {
						$having = $ret['having'];
					}
				}
				else {
					$where = $ret;
				}
			}

			// get the export method the user has chosen
			$method = ISC_ADMIN_EXPORTMETHOD_FACTORY::GetExportMethod($_REQUEST['format']);
			$method_details = $method->GetMethodDetails();

			$options = new ISC_ADMIN_EXPORTOPTIONS();
			$options->setFileType($this->filetype)
				->setTemplateId($templateid)
				->setWhere($where)
				->setHaving($having);

			// Initialise the export
			$method->Init($options);

			// run the export
			$file = $method->HandleToDo('ExportIntro');

			exit;
		}
		catch (Exception $ex) {
			FlashMessage($ex->getMessage(), MSG_ERROR);
			$this->StartExport();
		}
	}