Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
ebef63 1 <?php
MB 2
3
4 class plugin_directive_snippets extends plugin_base
5 {
6     var $module;
7     var $form;
8     var $tab;
9     var $record_id;
10     var $formdef;
11     var $options;
12
13     public function onShow()
14     {
15         global $app;
16
17         $listTpl = new tpl;
18         $listTpl->newTemplate('templates/web_directive_snippets.htm');
19
20         //* Loading language file
21         $lng_file = "lib/lang/".$_SESSION["s"]["language"]."_web_directive_snippets.lng";
22
23         include $lng_file;
24         $listTpl->setVar($wb);
25
26         $message = '';
27         $error   = '';
28
29         $server_type = $app->getconf->get_server_config($this->form->dataRecord['server_id'], 'web');
30         $server_type = $server_type['server_type'];
31         $records = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND type = ? ORDER BY name ASC", $server_type);
32
33         for ($i = 0, $c = count($records); $i < $c; $i++)
34         {
35             $records[$i]['is_selected'] = false;
36
37             if ($this->form->dataRecord['directive_snippets_id'] === $records[$i]['directive_snippets_id'])
38                 $records[$i]['is_selected'] = true;
39         }
40
41         $listTpl->setLoop('records', $records);
42
43         $list_name = 'directive_snippets_list';
44         $_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
45         $_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
46         $_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
47         $_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
48         $_SESSION["s"]["form"]["return_to"] = $list_name;
49
50         return $listTpl->grab();
51     }
52     
53     public function onUpdate()
54     {
55         global $app, $conf;
56
57         if (isset($this->form->dataRecord['directive_snippets_id']) && $this->form->oldDataRecord['directive_snippets_id'] !== $this->form->dataRecord['directive_snippets_id']) {
58             $app->db->query('UPDATE web_domain SET directive_snippets_id = ? WHERE domain_id = ?', $this->form->dataRecord['directive_snippets_id'], $this->form->id);
59         }
60     }
61
62     public function onInsert()
63     {
64         global $app, $conf;
65
66         if (isset($this->form->dataRecord['directive_snippets_id'])) {
67             $app->db->query('UPDATE web_domain SET directive_snippets_id = ? WHERE domain_id = ?', $this->form->dataRecord['directive_snippets_id'], $this->form->id);
68         }
69     }
70
71 }
1fa8f4 72 ?>