protected function createTemplateForService($id_service) { global $currentIndex; $currentIndex = $_SERVER['SCRIPT_NAME'] . (($controller = Tools::getValue('controller')) ? '?controller=' . $controller : ''); $url = $currentIndex . '&token=' . Tools::getAdminTokenLite('AdminMoussiqFree'); $obj = new $this->className((int) $id_service); if (Validate::isLoadedObject($obj)) { $tpl = ''; $path = dirname(__FILE__) . '/templates/'; if ((!file_exists($path) || !is_dir($path)) && !mkdir($path, 0777)) { $this->_errors[] = $this->l('Please create "templates" directory in your moussique free folder'); return false; } elseif (!is_writable($path)) { $this->_errors[] = $this->l('Your "templates" directory is not writeable.'); return false; } $exportFields = array('name', 'template', 'enclosure', 'delimiter', 'header'); foreach ($exportFields as $prop) { if (!property_exists($obj, $prop)) { $this->_errors[] = $this->l('Missing property:') . ' "' . $prop . '"'; return false; } $tpl .= base64_encode($prop) . ':' . base64_encode($obj->{$prop}) . "\n"; } if (!sizeof($this->_errors) && trim($tpl) != '') { $handler = fopen($path . Export::transliterate(str_replace(' ', '_', $obj->name)) . '.mtpl', 'w'); if (!$handler) { $this->_errors[] = $this->l('Could not create template file'); return false; } fwrite($handler, $tpl); fclose($handler); Tools::redirectAdmin($url . '&id_moussiqfree_service=' . $obj->id . '&updatemoussiqfree_service&tplFile=' . Export::transliterate(str_replace(' ', '_', $obj->name))); } else { $this->_errors[] = $this->l('Unable to select necessary template fields'); return false; } } $this->_errors[] = $this->l('Unable to load selected service'); return false; }