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