10 function PlugTemplate($table, $primarykey, $namekey, $descriptionkey='')
12 $this->table = $table;
13 $this->idkey = '`'.$primarykey.'`';
14 $this->namekey = '`'.$namekey.'`';
15 $this->desckey = '`'.$descriptionkey.'`';
18 function getIdFromName($name)
20 return quickQuery('SELECT '.$this->idkey.' as result FROM '.$this->table.' WHERE '.$this->namekey.'="'.addslashes($name).'"');
23 function getNameFromID($id)
25 return quickQuery('SELECT '.$this->namekey.' as result FROM '.$this->table.' WHERE '.$this->idkey.'='.intval($id));
28 function getDataFromID($dataname, $id)
30 return quickQuery('SELECT `'.addslashes($dataname).'` as result FROM '.$this->table.' WHERE '.$this->idkey.'='.intval($id));
33 function exists($name)
35 $res = sql_query('SELECT * FROM '.$this->table.' WHERE '.$this->namekey.'="'.addslashes($name).'"');
36 return (mysql_num_rows($res) != 0);
39 function existsID($id)
41 $res = sql_query('select * FROM '.$this->table.' WHERE '.$this->idkey.'='.intval($id));
42 return (mysql_num_rows($res) != 0);
45 function getTemplateList($w='', $s='')
48 if ($w != '') $where = ' WHERE '.$w;
50 $query = 'SELECT '.$this->idkey.' as id, '.$this->namekey.' as name';
51 if ($this->desckey) $query .= ', '.$this->desckey.' as description';
52 if ($s) $query .= ', '.$s;
53 $query .= ' FROM '.$this->table. $where .' ORDER BY '.$this->namekey;
55 $res = sql_query($query);
57 while ($a = mysql_fetch_assoc($res)) {
63 function getTemplateDesc($id)
65 $where = ' WHERE '.$this->idkey.'='.intval($id);
66 $query = 'SELECT '.$this->idkey.' as id, '.$this->namekey.' as name';
67 if ($this->desckey) $query .= ', '.$this->desckey.' as description';
68 $query .= ' FROM '.$this->table. $where .' ORDER BY '.$this->namekey;
70 $res = sql_query($query);
71 return mysql_fetch_assoc($res);
76 $query = 'SELECT * FROM '.$this->table.' WHERE '.$this->namekey.'="'.addslashes($name).'"';
77 $res = sql_query($query);
78 return mysql_fetch_assoc($res);
81 function readFromID($id)
83 $query = 'SELECT * FROM '.$this->table.' WHERE '.$this->idkey.'='.intval($id);
84 $res = sql_query($query);
85 return mysql_fetch_assoc($res);
88 function createTemplate($name, $desc='')
90 $query = 'INSERT INTO '.$this->table.' SET '.$this->namekey.'="'. addslashes($name).'"';
91 if ($desc && $this->desckey) $query .= ', '.$this->desckey.'="'.addslashes($desc).'"';
93 $newid = mysql_insert_id();
97 function updateTemplate($id, $template)
99 $query = 'UPDATE '.$this->table.' SET ';
100 foreach ($template as $k => $v) {
101 $query .= $k.'="'.addslashes($v).'",';
103 $query = substr($query,0,-1);
104 $query .= ' WHERE '.$this->idkey.'='.intval($id);
108 function deleteTemplate($id)
110 sql_query('DELETE FROM '.$this->table.' WHERE '.$this->idkey.'=' . intval($id));