From 3f8d5d90e1df5a7d12f8af3319eeee6afac7789f Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Wed, 13 Aug 2025 22:20:24 +0200 Subject: [PATCH] Template/Update (Part 36) * convert dbtype 'mail' --- endpoints/mail/mail.php | 178 +++++++++++++++++++++++++ endpoints/mails/mails.php | 59 ++++++++ pages/mail.php | 169 ----------------------- pages/mails.php | 48 ------- setup/tools/sqlgen/mailtemplate.ss.php | 24 ++-- template/listviews/mail.tpl | 11 +- 6 files changed, 259 insertions(+), 230 deletions(-) create mode 100644 endpoints/mail/mail.php create mode 100644 endpoints/mails/mails.php delete mode 100644 pages/mail.php delete mode 100644 pages/mails.php diff --git a/endpoints/mail/mail.php b/endpoints/mail/mail.php new file mode 100644 index 00000000..705c6aca --- /dev/null +++ b/endpoints/mail/mail.php @@ -0,0 +1,178 @@ +typeId = intVal($id); + $this->contribute = Type::getClassAttrib($this->type, 'contribute') ?? CONTRIBUTE_NONE; + } + + protected function generate() : void + { + $this->subject = new MailList(array(['id', $this->typeId])); + if ($this->subject->error) + $this->generateNotFound(Lang::game('mail'), Lang::mail('notFound')); + + $this->extendGlobalData($this->subject->getJSGlobals()); + + $this->h1 = Util::htmlEscape($this->subject->getField('name', true)); + + $this->gPageInfo += array( + 'type' => $this->type, + 'typeId' => $this->typeId, + 'name' => $this->subject->getField('name', true) + ); + + + /**************/ + /* Page Title */ + /**************/ + + array_unshift($this->title, $this->subject->getField('name', true), Util::ucFirst(Lang::game('mail'))); + + + /***********/ + /* Infobox */ + /***********/ + + $infobox = Lang::getInfoBoxForFlags($this->subject->getField('cuFlags')); + + // sender + delay + if ($this->typeId < 0) // def. achievement + { + if ($npcId = DB::World()->selectCell('SELECT `Sender` FROM achievement_reward WHERE `ID` = ?d', -$this->typeId)) + { + $infobox[] = Lang::mail('sender', ['[npc='.$npcId.']']); + $this->extendGlobalIds(Type::NPC, $npcId); + } + } + else if ($mlr = DB::World()->selectRow('SELECT * FROM mail_level_reward WHERE `mailTemplateId` = ?d', $this->typeId)) // level rewards + { + if ($mlr['level']) + $infobox[] = Lang::game('level').Lang::main('colon').$mlr['level']; + + if ($r = Lang::getRaceString($mlr['raceMask'], $rIds, Lang::FMT_MARKUP)) + { + $infobox[] = Lang::game('races').Lang::main('colon').$r; + $this->extendGlobalIds(Type::CHR_RACE, ...$rIds); + } + + $infobox[] = Lang::mail('sender', ['[npc='.$mlr['senderEntry'].']']); + $this->extendGlobalIds(Type::NPC, $mlr['senderEntry']); + } + else // achievement or quest + { + if ($q = DB::Aowow()->selectRow('SELECT `id`, `rewardMailDelay` FROM ?_quests WHERE `rewardMailTemplateId` = ?d', $this->typeId)) + { + if ($npcId= DB::World()->selectCell('SELECT `RewardMailSenderEntry` FROM quest_mail_sender WHERE `QuestId` = ?d', $q['id'])) + { + $infobox[] = Lang::mail('sender', ['[npc='.$npcId.']']); + $this->extendGlobalIds(Type::NPC, $npcId); + } + else if ($npcId = DB::Aowow()->selectCell('SELECT `typeId` FROM ?_quests_startend WHERE `questId` = ?d AND `type` = ?d AND `method` & ?d', $q['id'], Type::NPC, 0x2)) + { + $infobox[] = Lang::mail('sender', ['[npc='.$npcId.']']); + $this->extendGlobalIds(Type::NPC, $npcId); + } + + if ($q['rewardMailDelay'] > 0) + $infobox[] = Lang::mail('delay', [Util::formatTime($q['rewardMailDelay'] * 1000)]); + } + else if ($npcId = DB::World()->selectCell('SELECT `Sender` FROM achievement_reward WHERE `MailTemplateId` = ?d', $this->typeId)) + { + $infobox[] = Lang::mail('sender', ['[npc='.$npcId.']']); + $this->extendGlobalIds(Type::NPC, $npcId); + } + } + + if ($infobox) + $this->infobox = new InfoboxMarkup($infobox, ['allow' => Markup::CLASS_STAFF, 'dbpage' => true], 'infobox-contents0'); + + + /****************/ + /* Main Content */ + /****************/ + + $this->redButtons = array( + BUTTON_LINKS => ['type' => $this->type, 'typeId' => $this->typeId], + BUTTON_WOWHEAD => false + ); + + $this->extraText = new Markup(Util::parseHtmlText($this->subject->getField('text', true), true), ['dbpage' => true, 'allow' => Markup::CLASS_ADMIN], 'text-generic'); + + + /**************/ + /* Extra Tabs */ + /**************/ + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"], 'tabsRelated', true); + + // tab: attachment + if ($itemId = $this->subject->getField('attachment')) + { + $attachment = new ItemList(array(['id', $itemId])); + if (!$attachment->error) + { + $this->extendGlobalData($attachment->getJsGlobals()); + $this->lvTabs->addListviewTab(new Listview(array( + 'data' => $attachment->getListviewData(), + 'name' => Lang::mail('attachment'), + 'id' => 'attachment' + ), ItemList::$brickFile)); + } + } + + if ($this->typeId < 0 || // used by: achievement + ($acvId = DB::World()->selectCell('SELECT `ID` FROM achievement_reward WHERE `MailTemplateId` = ?d', $this->typeId))) + { + $ubAchievements = new AchievementList(array(['id', $this->typeId < 0 ? -$this->typeId : $acvId])); + if (!$ubAchievements->error) + { + $this->extendGlobalData($ubAchievements->getJsGlobals()); + $this->lvTabs->addListviewTab(new Listview(array( + 'data' => $ubAchievements->getListviewData(), + 'id' => 'used-by-achievement' + ), AchievementList::$brickFile)); + } + } + else // used by: quest + { + $ubQuests = new QuestList(array(['rewardMailTemplateId', $this->typeId])); + if (!$ubQuests->error) + { + $this->extendGlobalData($ubQuests->getJsGlobals()); + $this->lvTabs->addListviewTab(new Listview(array( + 'data' => $ubQuests->getListviewData(), + 'id' => 'used-by-quest' + ), QuestList::$brickFile)); + } + } + + parent::generate(); + } +} + +?> diff --git a/endpoints/mails/mails.php b/endpoints/mails/mails.php new file mode 100644 index 00000000..e892948f --- /dev/null +++ b/endpoints/mails/mails.php @@ -0,0 +1,59 @@ +getCategoryFromUrl($pageParam); + + parent::__construct($pageParam); + } + + protected function generate() : void + { + $this->h1 = Util::ucFirst(Lang::game('mails')); + + + /**************/ + /* Page Title */ + /**************/ + + array_unshift($this->title, $this->h1); + + + /****************/ + /* Main Content */ + /****************/ + + $tabData = []; + $mails = new MailList(); + if (!$mails->error) + $tabData['data'] = $mails->getListviewData(); + + $this->extendGlobalData($mails->getJsGlobals()); + + $this->lvTabs = new Tabs(['parent' => "\$\$WH.ge('tabs-generic')"]); + + $this->lvTabs->addListviewTab(new Listview(['data' => $mails->getListviewData()], MailList::$brickFile, 'mail')); + + parent::generate(); + } +} + +?> diff --git a/pages/mail.php b/pages/mail.php deleted file mode 100644 index 157188f4..00000000 --- a/pages/mail.php +++ /dev/null @@ -1,169 +0,0 @@ -typeId = intVal($id); - - $this->subject = new MailList(array(['id', $this->typeId])); - - if ($this->subject->error) - $this->notFound(lang::game('mail'), Lang::mail('notFound')); - - $this->extendGlobalData($this->subject->getJSGlobals()); - - $this->name = Util::htmlEscape(Util::ucFirst($this->subject->getField('name', true))); - } - - protected function generateContent() - { - /***********/ - /* Infobox */ - /***********/ - - $infobox = []; - - // sender + delay - if ($this->typeId < 0) // def. achievement - { - if ($npcId = DB::World()->selectCell('SELECT Sender FROM achievement_reward WHERE ID = ?d', -$this->typeId)) - { - $infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$npcId.']'; - $this->extendGlobalIds(Type::NPC, $npcId); - } - } - else if ($mlr = DB::World()->selectRow('SELECT * FROM mail_level_reward WHERE mailTemplateId = ?d', $this->typeId)) // level rewards - { - if ($mlr['level']) - $infobox[] = Lang::game('level').Lang::main('colon').$mlr['level']; - - $rIds = []; - if ($r = Lang::getRaceString($mlr['raceMask'], $rIds, Lang::FMT_MARKUP)) - { - $infobox[] = Lang::game('races').Lang::main('colon').$r; - $this->extendGlobalIds(Type::CHR_RACE, ...$rIds); - } - - $infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$mlr['senderEntry'].']'; - $this->extendGlobalIds(Type::NPC, $mlr['senderEntry']); - } - else // achievement or quest - { - if ($q = DB::Aowow()->selectRow('SELECT id, rewardMailDelay FROM ?_quests WHERE rewardMailTemplateId = ?d', $this->typeId)) - { - if ($npcId= DB::World()->selectCell('SELECT RewardMailSenderEntry FROM quest_mail_sender WHERE QuestId = ?d', $q['id'])) - { - $infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$npcId.']'; - $this->extendGlobalIds(Type::NPC, $npcId); - } - else if ($npcId = DB::Aowow()->selectCell('SELECT typeId FROM ?_quests_startend WHERE questId = ?d AND type = ?d AND method & ?d', $q['id'], Type::NPC, 0x2)) - { - $infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$npcId.']'; - $this->extendGlobalIds(Type::NPC, $npcId); - } - - if ($q['rewardMailDelay'] > 0) - $infobox[] = Lang::mail('delay').Lang::main('colon').''.Util::formatTime($q['rewardMailDelay'] * 1000); - } - else if ($npcId = DB::World()->selectCell('SELECT Sender FROM achievement_reward WHERE MailTemplateId = ?d', $this->typeId)) - { - $infobox[] = Lang::mail('sender').Lang::main('colon').'[npc='.$npcId.']'; - $this->extendGlobalIds(Type::NPC, $npcId); - } - } - - /****************/ - /* Main Content */ - /****************/ - - $this->infobox = $infobox ? '[ul][li]'.implode('[/li][li]', $infobox).'[/li][/ul]' : ''; - $this->redButtons = array( - BUTTON_LINKS => ['type' => $this->type, 'typeId' => $this->typeId], - BUTTON_WOWHEAD => false - ); - - $this->extraText = Util::parseHtmlText($this->subject->getField('text', true), true); - - - /**************/ - /* Extra Tabs */ - /**************/ - - // tab: attachment - if ($itemId = $this->subject->getField('attachment')) - { - $attachment = new ItemList(array(['id', $itemId])); - if (!$attachment->error) - { - $this->extendGlobalData($attachment->getJsGlobals()); - $this->lvTabs[] = [ItemList::$brickFile, array( - 'data' => array_values($attachment->getListviewData()), - 'name' => Lang::mail('attachment'), - 'id' => 'attachment' - )]; - } - } - - - if ($this->typeId < 0 || // used by: achievement - ($acvId = DB::World()->selectCell('SELECT ID FROM achievement_reward WHERE MailTemplateId = ?d', $this->typeId))) - { - $ubAchievements = new AchievementList(array(['id', $this->typeId < 0 ? -$this->typeId : $acvId])); - if (!$ubAchievements->error) - { - $this->extendGlobalData($ubAchievements->getJsGlobals()); - $this->lvTabs[] = [AchievementList::$brickFile, array( - 'data' => array_values($ubAchievements->getListviewData()), - 'id' => 'used-by-achievement' - )]; - } - } - else if ($npcId = DB::World()->selectCell('SELECT ID FROM achievement_reward WHERE MailTemplateId = ?d', $this->typeId)) - { - $infobox[] = '[Sender]: [npc='.$npcId.']'; - $this->extendGlobalIds(Type::NPC, $npcId); - } - - else // used by: quest - { - $ubQuests = new QuestList(array(['rewardMailTemplateId', $this->typeId])); - if (!$ubQuests->error) - { - $this->extendGlobalData($ubQuests->getJsGlobals()); - $this->lvTabs[] = [QuestList::$brickFile, array( - 'data' => array_values($ubQuests->getListviewData()), - 'id' => 'used-by-quest' - )]; - } - } - } - - protected function generateTitle() - { - array_unshift($this->title, Util::ucFirst($this->subject->getField('name', true)), Util::ucFirst(Lang::game('mail'))); - } - - protected function generatePath() { } -} - -?> diff --git a/pages/mails.php b/pages/mails.php deleted file mode 100644 index 391b575f..00000000 --- a/pages/mails.php +++ /dev/null @@ -1,48 +0,0 @@ -name = Util::ucFirst(Lang::game('mails')); - } - - protected function generateContent() - { - $tabData = []; - $mails = new MailList(); - if (!$mails->error) - $tabData['data'] = array_values($mails->getListviewData()); - - $this->extendGlobalData($mails->getJsGlobals()); - - $this->lvTabs[] = [MailList::$brickFile, $tabData, 'mail']; - } - - protected function generateTitle() - { - array_unshift($this->title, $this->name); - } - - protected function generatePath() { } -} - -?> diff --git a/setup/tools/sqlgen/mailtemplate.ss.php b/setup/tools/sqlgen/mailtemplate.ss.php index 32c21948..d2e17d1e 100644 --- a/setup/tools/sqlgen/mailtemplate.ss.php +++ b/setup/tools/sqlgen/mailtemplate.ss.php @@ -28,17 +28,17 @@ CLISetup::registerSetup("sql", new class extends SetupScript CLI::write('[mails] - loading data from achievement_reward'); $acvMail = DB::World()->select( - 'SELECT -ar.ID, 0, - IFNULL(ar.Subject, "") AS s0, IFNULL(arl2.Subject, "") AS s2, IFNULL(arl3.Subject, "") AS s3, IFNULL(arl4.Subject, "") AS s4, IFNULL(arl6.Subject, "") AS s6, IFNULL(arl8.Subject, "") AS s8, - IFNULL(ar.Body, "") AS t0, IFNULL(arl2.Body, "") AS t2, IFNULL(arl3.Body, "") AS t3, IFNULL(arl4.Body, "") AS t4, IFNULL(arl6.Body, "") AS t6, IFNULL(arl8.Body, "") AS t8, - ItemID + 'SELECT -ar.`ID`, 0, + IFNULL(ar.`Subject`, "") AS "s0", IFNULL(arl2.`Subject`, "") AS "s2", IFNULL(arl3.`Subject`, "") AS "s3", IFNULL(arl4.`Subject`, "") AS "s4", IFNULL(arl6.`Subject`, "") AS "s6", IFNULL(arl8.`Subject`, "") AS "s8", + IFNULL(ar.`Body`, "") AS "t0", IFNULL(arl2.`Body`, "") AS "t2", IFNULL(arl3.`Body`, "") AS "t3", IFNULL(arl4.`Body`, "") AS "t4", IFNULL(arl6.`Body`, "") AS "t6", IFNULL(arl8.`Body`, "") AS "t8", + `ItemID` FROM achievement_reward ar - LEFT JOIN achievement_reward_locale arl2 ON ar.ID = arl2.ID AND arl2.Locale = "frFR" - LEFT JOIN achievement_reward_locale arl3 ON ar.ID = arl3.ID AND arl3.Locale = "deDE" - LEFT JOIN achievement_reward_locale arl4 ON ar.ID = arl4.ID AND arl4.Locale = "zhCN" - LEFT JOIN achievement_reward_locale arl6 ON ar.ID = arl6.ID AND arl6.Locale = "esES" - LEFT JOIN achievement_reward_locale arl8 ON ar.ID = arl8.ID AND arl8.Locale = "ruRU" - WHERE ar.MailTemplateID = 0 AND ar.Body <> ""' + LEFT JOIN achievement_reward_locale arl2 ON ar.`ID` = arl2.`ID` AND arl2.`Locale` = "frFR" + LEFT JOIN achievement_reward_locale arl3 ON ar.`ID` = arl3.`ID` AND arl3.`Locale` = "deDE" + LEFT JOIN achievement_reward_locale arl4 ON ar.`ID` = arl4.`ID` AND arl4.`Locale` = "zhCN" + LEFT JOIN achievement_reward_locale arl6 ON ar.`ID` = arl6.`ID` AND arl6.`Locale` = "esES" + LEFT JOIN achievement_reward_locale arl8 ON ar.`ID` = arl8.`ID` AND arl8.`Locale` = "ruRU" + WHERE ar.`MailTemplateID` = 0 AND ar.`Body` <> ""' ); DB::Aowow()->query('INSERT INTO ?_mails VALUES (?a)', array_values($acvMail)); @@ -46,9 +46,9 @@ CLISetup::registerSetup("sql", new class extends SetupScript CLI::write('[mails] - loading data from mail_loot_template'); // assume mails to only contain one single item, wich works for an unmodded installation - $mlt = DB::World()->selectCol('SELECT Entry AS ARRAY_KEY, Item FROM mail_loot_template'); + $mlt = DB::World()->selectCol('SELECT `Entry` AS ARRAY_KEY, `Item` FROM mail_loot_template'); foreach ($mlt as $k => $v) - DB::Aowow()->query('UPDATE ?_mails SET attachment = ?d WHERE id = ?d', $v, $k); + DB::Aowow()->query('UPDATE ?_mails SET `attachment` = ?d WHERE `id` = ?d', $v, $k); return true; } diff --git a/template/listviews/mail.tpl b/template/listviews/mail.tpl index 2ebe19f4..72e05fda 100644 --- a/template/listviews/mail.tpl +++ b/template/listviews/mail.tpl @@ -11,7 +11,9 @@ Listview.templates.mail = { value: 'id', compute: function(data, td) { if (data.id) { - $WH.ae(td, $WH.ct(data.id)); + let pre = $WH.ce('pre', { style: { display: 'inline', margin: '0' }}, $WH.ct(data.id)); + $WH.clickToCopy(pre); + $WH.ae(td, pre); } } }, @@ -89,5 +91,12 @@ Listview.templates.mail = { ], getItemLink: function(mail) { return '?mail=' + mail.id; + }, + onBeforeCreate : function() { + // hide duplicate id col + if (this.debug || g_user?.debug) { + let colId = this.columns.findIndex(x => x.id == 'id'); + this.visibility = this.visibility.filter(x => x != colId); + } } }