/** * Writes the skins and templates to the database * * @param $allowOverwrite * set to 1 when allowed to overwrite existing skins with the same name * (default = 0) */ function writeToDatabase($allowOverwrite = 0) { $existingSkins = $this->checkSkinNameClashes(); $existingTemplates = $this->checkTemplateNameClashes(); // if not allowed to overwrite, check if any nameclashes exists if (!$allowOverwrite) { if (sizeof($existingSkins) > 0 || sizeof($existingTemplates) > 0) { return _SKINIE_NAME_CLASHES_DETECTED; } } foreach ($this->skins as $skinName => $data) { // 1. if exists: delete all part data, update desc data // if not exists: create desc if (in_array($skinName, $existingSkins)) { $skinObj = SKIN::createFromName($skinName); // delete all parts of the skin $skinObj->deleteAllParts(); // update general info $skinObj->updateGeneralInfo($skinName, $data['description'], $data['type'], $data['includeMode'], $data['includePrefix']); } else { $skinid = SKIN::createNew($skinName, $data['description'], $data['type'], $data['includeMode'], $data['includePrefix']); $skinObj = new SKIN($skinid); } // 2. add parts foreach ($data['parts'] as $partName => $partContent) { $skinObj->update($partName, $partContent); } } foreach ($this->templates as $templateName => $data) { // 1. if exists: delete all part data, update desc data // if not exists: create desc if (in_array($templateName, $existingTemplates)) { $templateObj = TEMPLATE::createFromName($templateName); // delete all parts of the template $templateObj->deleteAllParts(); // update general info $templateObj->updateGeneralInfo($templateName, $data['description']); } else { $templateid = TEMPLATE::createNew($templateName, $data['description']); $templateObj = new TEMPLATE($templateid); } // 2. add parts foreach ($data['parts'] as $partName => $partContent) { $templateObj->update($partName, $partContent); } } }
/** * @todo document this */ function action_templateclone() { global $member; $templateid = intRequestVar('templateid'); $member->isAdmin() or $this->disallow(); // 1. read old template $name = TEMPLATE::getNameFromId($templateid); $desc = TEMPLATE::getDesc($templateid); // 2. create desc thing $name = "cloned" . $name; // if a template with that name already exists: if (TEMPLATE::exists($name)) { $i = 1; while (TEMPLATE::exists($name . $i)) { $i++; } $name .= $i; } $newid = TEMPLATE::createNew($name, $desc); // 3. create clone // go through parts of old template and add them to the new one $res = sql_query('SELECT tpartname, tcontent FROM ' . sql_table('template') . ' WHERE tdesc=' . $templateid); while ($o = sql_fetch_object($res)) { $this->addToTemplate($newid, $o->tpartname, $o->tcontent); } $this->action_templateoverview(); }