/** * Add a layout * @param <type> $layout * @param <type> $description * @param <type> $tags * @param <type> $userid * @param <type> $templateId * @param <type> $templateId * @param <string> $xml Use the provided XML instead of a template * @return <type> */ public function Add($layout, $description, $tags, $userid, $templateId, $resolutionId, $xml = '') { Debug::LogEntry('audit', 'Adding new Layout', 'Layout', 'Add'); try { $dbh = PDOConnect::init(); $currentdate = date("Y-m-d H:i:s"); // We must provide either a template or a resolution if ($templateId == 0 && $resolutionId == 0 && $xml == '') { $this->ThrowError(__('To add a Layout either a Template or Resolution must be provided')); } // Validation if (strlen($layout) > 50 || strlen($layout) < 1) { $this->ThrowError(25001, __("Layout Name must be between 1 and 50 characters")); } if (strlen($description) > 254) { $this->ThrowError(25002, __("Description can not be longer than 254 characters")); } if (strlen($tags) > 254) { $this->ThrowError(25003, __("Tags can not be longer than 254 characters")); } // Ensure there are no layouts with the same name $sth = $dbh->prepare('SELECT layout FROM `layout` WHERE layout = :layout AND userID = :userid'); $sth->execute(array('layout' => $layout, 'userid' => $userid)); if ($row = $sth->fetch()) { $this->ThrowError(25004, sprintf(__("You already own a layout called '%s'. Please choose another name."), $layout)); } Debug::LogEntry('audit', 'Validation Compelte', 'Layout', 'Add'); // End Validation // Are we coming from a template? if ($templateId != '' && $templateId != 0) { // Copy the template layout and adjust if (!($id = $this->Copy($templateId, $layout, $description, $userid, true))) { throw new Exception(__('Unable to use this template')); } } else { // We should use the resolution or the provided XML. if ($xml != '') { $initialXml = $xml; } else { // Do we have a template? if (!($initialXml = $this->GetInitialXml($resolutionId, $userid))) { throw new Exception(__('Unable to get initial XML')); } } Debug::LogEntry('audit', 'Retrieved template xml', 'Layout', 'Add'); $SQL = 'INSERT INTO layout (layout, description, userID, createdDT, modifiedDT, xml, status)'; $SQL .= ' VALUES (:layout, :description, :userid, :createddt, :modifieddt, :xml, :status)'; $sth = $dbh->prepare($SQL); $sth->execute(array('layout' => $layout, 'description' => $description, 'userid' => $userid, 'createddt' => $currentdate, 'modifieddt' => $currentdate, 'xml' => $initialXml, 'status' => 3)); $id = $dbh->lastInsertId(); // Create a campaign $campaign = new Campaign($this->db); $campaignId = $campaign->Add($layout, 1, $userid); $campaign->Link($campaignId, $id, 0); // What permissions should we create this with? if (Config::GetSetting('LAYOUT_DEFAULT') == 'public') { $security = new CampaignSecurity($this->db); $security->LinkEveryone($campaignId, 1, 0, 0); // Permissions on the new region(s)? $layout = new Layout($this->db); foreach ($layout->GetRegionList($id) as $region) { $security = new LayoutRegionGroupSecurity($this->db); $security->LinkEveryone($id, $region['regionid'], 1, 0, 0); } } } // By this point we should have a layout record created // Are there any tags? if ($tags != '') { // Create an array out of the tags $tagsArray = explode(',', $tags); // Add the tags XML to the layout if (!$this->EditTags($id, $tagsArray)) { $this->ThrowError(__('Unable to edit tags')); } } Debug::LogEntry('audit', 'Complete', 'Layout', 'Add'); return $id; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { $this->SetError(25005, __('Could not add Layout')); } return false; } }
/** * Add a layout * @param <type> $layout * @param <type> $description * @param <type> $tags * @param <type> $userid * @param <type> $templateId * @return <type> */ public function Add($layout, $description, $tags, $userid, $templateId) { Debug::LogEntry('audit', 'Adding new Layout', 'Layout', 'Add'); try { $dbh = PDOConnect::init(); $currentdate = date("Y-m-d H:i:s"); // Validation if (strlen($layout) > 50 || strlen($layout) < 1) { $this->ThrowError(25001, __("Layout Name must be between 1 and 50 characters")); } if (strlen($description) > 254) { $this->ThrowError(25002, __("Description can not be longer than 254 characters")); } if (strlen($tags) > 254) { $this->ThrowError(25003, __("Tags can not be longer than 254 characters")); } // Ensure there are no layouts with the same name $sth = $dbh->prepare('SELECT layout FROM `layout` WHERE layout = :layout AND userID = :userid'); $sth->execute(array('layout' => $layout, 'userid' => $userid)); if ($row = $sth->fetch()) { $this->ThrowError(25004, sprintf(__("You already own a layout called '%s'. Please choose another name."), $layout)); } Debug::LogEntry('audit', 'Validation Compelte', 'Layout', 'Add'); // End Validation // Get the XML for this template. $templateXml = $this->GetTemplateXml($templateId, $userid); Debug::LogEntry('audit', 'Retrieved template xml', 'Layout', 'Add'); $SQL = 'INSERT INTO layout (layout, description, userID, createdDT, modifiedDT, tags, xml, status)'; $SQL .= ' VALUES (:layout, :description, :userid, :createddt, :modifieddt, :tags, :xml, :status)'; $sth = $dbh->prepare($SQL); $sth->execute(array('layout' => $layout, 'description' => $description, 'userid' => $userid, 'createddt' => $currentdate, 'modifieddt' => $currentdate, 'tags' => $tags, 'xml' => $templateXml, 'status' => 3)); $id = $dbh->lastInsertId(); Debug::LogEntry('audit', 'Updating Tags', 'Layout', 'Add'); // Are there any tags? if ($tags != '') { // Create an array out of the tags $tagsArray = explode(' ', $tags); // Add the tags XML to the layout if (!$this->EditTags($id, $tagsArray)) { $this->ThrowError(__('Unable to edit tags')); } } // Create a campaign $campaign = new Campaign($this->db); $campaignId = $campaign->Add($layout, 1, $userid); $campaign->Link($campaignId, $id, 0); // What permissions should we create this with? if (Config::GetSetting('LAYOUT_DEFAULT') == 'public') { Kit::ClassLoader('campaignsecurity'); $security = new CampaignSecurity($this->db); $security->LinkEveryone($campaignId, 1, 0, 0); } Debug::LogEntry('audit', 'Complete', 'Layout', 'Add'); return $id; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { $this->SetError(25005, __('Could not add Layout')); } return false; } }