Blame view

libs/extra.class.php 2.3 KB
1ccf6db7   andryeyev   + класс Extra для...
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  <?php
  
  class Extra
  {
      var $db = null;
      var $tpl = null;
      var $error = null;
      var $cache = null;
      
      public function __construct (&$db, &$tpl, &$error, &$cache)
      {
          $this->db = &$db;
          $this->tpl = &$tpl;
          $this->error = &$error;
          $this->cache = &$cache;
      }
  
      public function trim (&$data)
      {
          foreach ($data as $key => $value)
          { 
              if (! is_array ($data[$key]))
              {
                  $data[$key] = trim ($value);
              }
          }
      }
      
      public function valid ($data, $upload = null)
      {
          return true;
      }
   
      public function getAll ()
      {     
          return $this->db->getAll('
              SELECT *
              FROM `extra`
                  INNER JOIN `extra_status` ON `extra_status`.status_id = `extra`.status_id
          ', array (), DB_FETCHMODE_ASSOC);
      }
   
      public function init ()
      {  
          // assign var
          $this->tpl->assign('mass', array (
              'extra' => $this->getAll(),
          ));
          
          // assign template
          $this->tpl->assign("tpl", "extra.tpl");
      }
  
      public function getOneByName ($NAME)
      {
          return $this->db->getRow('
              SELECT *
              FROM `extra`
                  INNER JOIN `extra_status` ON `extra_status`.status_id = `extra`.status_id
              WHERE `extra`.extra_name=?
          ', array ($NAME), DB_FETCHMODE_ASSOC); 
      }
  
      public function getOneById ($id)
      {
          return $this->db->getRow('
              SELECT *
              FROM `extra`
                  INNER JOIN `extra_status` ON `extra_status`.status_id = `extra`.status_id
              WHERE `extra`.extra_id=?
          ', array ($id), DB_FETCHMODE_ASSOC);
      }
      
      public function getStatusIdByName ($NAME)
      {
          $result = $this->getOneByName ($NAME);
          
          return $result['status_id'];
      }
  
      public function setExtraStatus ($param)
      {
          return $this->db->query('
              UPDATE `extra`
              SET status_id = '.(int)$param['status_id'].'
              WHERE extra_id = '.(int)$param['extra_id'].'
          ');
      }
      
      public function displaySnow () 
      {
          return '
          <link rel="stylesheet" type="text/css" href="/js/snowstorm.css" />
          ';
          // <script src="/js/snowstorm.js"></script> 
      }
  }