public function HandleToDo($do) { $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->LoadLangFile('export'); $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->LoadLangFile('exporttemplates'); $this->templates = GetClass('ISC_ADMIN_EXPORTTEMPLATES'); $this->type = isc_strtolower($_GET['t']); // load the file type for this export if (!$this->filetype = ISC_ADMIN_EXPORTFILETYPE_FACTORY::GetExportFileType($this->type)) { FlashMessage(GetLang("InvalidType"), MSG_ERROR, 'index.php?ToDo=viewExportTemplates'); } // does user have permission to export this type? if (!$this->filetype->HasPermission() || !gzte11(ISC_MEDIUMPRINT)) { $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->DoHomePage(GetLang('Unauthorized'), MSG_ERROR); } $details = $this->filetype->GetTypeDetails(); $title = $details['title']; $this->type_title = $title; $this->title = sprintf(GetLang("ExportTitle"), $title); switch (isc_strtolower($do)) { case 'startexport': $GLOBALS['BreadcrumEntries'] = array(GetLang('Home') => "index.php", $title => $details['viewlink'], GetLang('Export') => ""); if (!isset($_REQUEST['ajax'])) { $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->PrintHeader(); } $this->StartExport(); if (!isset($_REQUEST['ajax'])) { $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->PrintFooter(); } break; case 'runexport': $GLOBALS['BreadcrumEntries'] = array(GetLang('Home') => "index.php", GetLang('Export') => "", $title => ""); $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->PrintHeader(); $this->RunExport(); $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->PrintFooter(); } }
private function RunExport() { try { // check for a selected template if (!isset($_POST["template"]) || !$_POST["template"]) { throw new Exception(GetLang("NoTemplateSelected")); } if (!isset($_POST['format'])) { throw new Exception(GetLang("NoMethodSelected")); } $templateid = $_POST["template"]; // 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)); } $where = ""; // get the custom search fields if (isset($_POST['ids'])) { $ids = explode(',', $_POST['ids']); $ids = implode(', ', array_map(array($GLOBALS['ISC_CLASS_DB'], "Quote"), $ids)); $details = $this->filetype->GetTypeDetails(); $where = $details['idfield'] . " IN (" . $_POST["ids"] . ")"; } elseif (isset($_POST['searchId'])) { // get the where statement for this search $ret = $this->filetype->GetWhereFromSearch($_POST['searchId']); $where = $ret['where']; } elseif (isset($_POST['params'])) { $params = $this->GetParams($_POST['params']); $where = $this->filetype->GetWhereFromParams($params); } //$_SESSION['mywhere'] = $where; // this variable used in the function ExportRows() by blessen // get the export method the user has chosen $method = ISC_ADMIN_EXPORTMETHOD_FACTORY::GetExportMethod($_POST['format']); // Initialise the export $method->Init($this->filetype, $templateid, $where, $this->vendorid); $details = $this->filetype->GetTypeDetails(); if ($_POST['format'] == "CSV" && $details['name'] == "customers" && $method->settings['AltCustomers']) { // hackery to use alternate customers class $this->filetype = ISC_ADMIN_EXPORTFILETYPE_FACTORY::GetExportFileType("customersalt"); // reinitialise the method with alternate file type $method->Init($this->filetype, $templateid, $where, $this->vendorid); } // run the export $file = $method->Export(); $method_details = $method->GetMethodDetails(); // log the export $GLOBALS['ISC_CLASS_LOG']->LogAdminAction($this->type_title, $template['exporttemplatename'], $method_details['name']); // send the file to the user DownloadFile($file, $this->type . "-" . isc_date("Y-m-d") . "." . $method_details['extension']); exit; } catch (Exception $ex) { FlashMessage($ex->getMessage(), MSG_ERROR); $this->StartExport(); } }
/** * Updates the order of fields in an export template * **/ private function UpdateTemplateFields() { $GLOBALS['ISC_CLASS_ADMIN_ENGINE']->LoadLangFile('exporttemplates'); $field_type = $_REQUEST['l']; $template_id = $_REQUEST["tempId"]; $templates = GetClass('ISC_ADMIN_EXPORTTEMPLATES'); try { $template = $templates->GetTemplate($template_id); if ($template['builtin']) { die; } } catch (Exception $ex) { die; } require_once APP_ROOT . "/includes/exporter/class.exportfiletype.factory.php"; $type = ISC_ADMIN_EXPORTFILETYPE_FACTORY::GetExportFileType($field_type); $fields = $type->LoadFields(); foreach ($_POST[$field_type . "FieldList"] as $order => $field) { $field_id = substr($field, strpos($field, "-") + 1); if (!isset($fields[$field_id])) { continue; } //check if field exists $query = "SELECT exporttemplatefieldid FROM [|PREFIX|]export_template_fields WHERE fieldid = '" . $GLOBALS['ISC_CLASS_DB']->Quote($field_id) . "' AND fieldtype = '" . $GLOBALS['ISC_CLASS_DB']->Quote($field_type) . "' AND exporttemplateid = '" . $GLOBALS['ISC_CLASS_DB']->Quote($template_id) . "'"; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); if ($GLOBALS['ISC_CLASS_DB']->CountResult($result)) { $row = $GLOBALS['ISC_CLASS_DB']->Fetch($result); // update existing field $query = "UPDATE [|PREFIX|]export_template_fields SET sortorder = {$order} WHERE exporttemplatefieldid = " . $row['exporttemplatefieldid']; $GLOBALS['ISC_CLASS_DB']->Query($query); } else { // create field $field_array = array("exporttemplateid" => $template_id, "fieldid" => $field_id, "fieldtype" => $field_type, "fieldname" => $fields[$field_id]['label'], "includeinexport" => 0, "sortorder" => $order); $GLOBALS['ISC_CLASS_DB']->InsertQuery('export_template_fields', $field_array); } $query = "UPDATE [|PREFIX|]export_template_fields SET sortorder = {$order} WHERE fieldid = '" . $GLOBALS['ISC_CLASS_DB']->Quote($field_id) . "' AND fieldtype = '" . $GLOBALS['ISC_CLASS_DB']->Quote($field_type) . "' AND exporttemplateid = '" . $GLOBALS['ISC_CLASS_DB']->Quote($template_id) . "'"; $GLOBALS['ISC_CLASS_DB']->Query($query); } $tags[] = $this->MakeXMLTag('status', 1); $tags[] = $this->MakeXMLTag('message', sprintf(GetLang('FieldOrderUpdated'), $field_type), true); $this->SendXMLHeader(); $this->SendXMLResponse($tags); die; }
/** * Sets the template globals to create a file type (tab, grid, used check box, javascript) * * @param mixed $templateid * @param mixed $usedTypes * @param mixed $load_from_post */ private function SetTypeData($templateid = 0, $usedTypes = array(), $load_from_post = false) { // get a list of available file types $filetypes = ISC_ADMIN_EXPORTFILETYPE_FACTORY::GetExportFileTypeList(); $x = 2; $gridData = ""; $tabData = ""; $listJS = ""; $includeData = ""; $includeJS = ""; $verifyJS = ""; if ($templateid == 0 && !$load_from_post) { $use_defaults = true; } else { $use_defaults = false; } foreach ($filetypes as $file => $details) { // get the fields for this type $type = ISC_ADMIN_EXPORTFILETYPE_FACTORY::GetExportFileType($details['name']); $use_id = $templateid; if ($load_from_post) { $use_id = 0; } $fields = $type->LoadFields($use_id); if ($load_from_post) { $fields = $this->LoadFieldsFromPost($fields, $details['name']); } $GLOBALS['FileIndex'] = $x; if ($use_defaults || in_array($details['name'], $usedTypes)) { $GLOBALS['IncludeChecked'] = "checked=\"checked\""; $GLOBALS['TabDisplay'] = ""; } else { $GLOBALS['IncludeChecked'] = ""; $GLOBALS['TabDisplay'] = "style=\"display: none;\""; } // create a tab for the type $GLOBALS['TypeTitle'] = $details['title']; $GLOBALS["ISC_CLASS_TEMPLATE"]->SetTemplate("exporttemplates.form.tab"); $tabData .= "\n" . $GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate(true); // get the grid data $ret = $this->GetFieldGrid($details['name'], $fields, $use_defaults); $GLOBALS['GridData'] = $ret["gridData"]; $GLOBALS['TypeName'] = $details['name']; $GLOBALS["ISC_CLASS_TEMPLATE"]->SetTemplate("exporttemplates.form.grid"); $GLOBALS['FieldGrid'] = $GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate(true); $GLOBALS['FileIndex'] = $x; $GLOBALS['TypeDisplay'] = "display: none;"; $GLOBALS['TypeWidth'] = ""; $GLOBALS["ISC_CLASS_TEMPLATE"]->SetTemplate("exporttemplates.form.type"); $gridData .= "\n\n" . $GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate(true); $listJS .= $ret["listJS"]; // generate a check box for this file type $GLOBALS['IncludeTypeLabel'] = sprintf(GetLang("AllowType"), $details['title']); $GLOBALS['IncludeType'] = $details['name']; $GLOBALS['YesIncludeType'] = sprintf(GetLang("YesAllowType"), isc_strtolower($details['title'])); $GLOBALS["ISC_CLASS_TEMPLATE"]->SetTemplate("exporttemplates.form.includetype"); $includeData .= "\n" . $GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate(true); // javascript for the checkbox to hide the tab $includeJS .= "\n\t\t\t \$(\"#include" . $details['name'] . "\").change(function() {\n\t\t\t\tif (this.checked)\n\t\t\t\t\t\$(\"#tab" . $x . "\").animate({ opacity: \"show\", color: \"green\" }, \"slow\").animate({color: \"#666\"}, \"medium\");\n\t\t\t\telse\n\t\t\t\t\t\$(\"#tab" . $x . "\").fadeOut(\"fast\");\n\t\t\t});\n"; // type verification js $verifyJS .= "\n\t\t\tif (!VerifyList('" . $details['name'] . "', " . $x . ")) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t"; $x++; } $GLOBALS['TypeTabs'] = $tabData; $GLOBALS['TypeGrids'] = $gridData; $GLOBALS['CreateLists'] = $listJS; $GLOBALS['IncludeTypes'] = $includeData; $GLOBALS['IncludeJS'] = $includeJS; $GLOBALS['VerifyJS'] = $verifyJS; }