tableName = DB_PREFIX_SERVICE.'Settings'; $this->DBObj($id); } function get($name, $field = 'value') { if (!empty($this) && get_class($this) == 'Settings') { $db = $this->db; } else { require_once ('class/DB/S_db2.php'); $db = S_db2::getInstance(); } $tableName = 'tbl'.DB_PREFIX_SERVICE.'Settings'; $sql = "SELECT * FROM {$db->$tableName} WHERE name = " . $db->quote($name); $arr = $db->queryRow($sql); return DBObj::getSubElem($arr, $field); } function getSettingsList() { $sql = " SELECT name FROM {$this->tableNameDB} WHERE 1 AND cat = ".$this->db->quote($this->cat, 'text')." ORDER BY id "; return $this->db->queryCol($sql); } function _getWhere4Grid($opt = array()) { return parent::_getWhere4Grid($opt). " AND {$this->tableName}.cat = ".$this->db->quote($this->cat, 'text')." "; } function getFieldList() { $ret = array(); $fields = $this->getSettingsList(); if (is_array($fields)){ foreach ($fields as $field) { $ret[] = array( 'field' => $field, 'type' => 'text', 'null' => '', 'key' => '', 'default' => '', 'extra' => '', ); } } return $ret; } function getFromDB($id, $field = false) { $sql = " SELECT {$this->tableName}.name, {$this->tableName}.value FROM {$this->tableNameDB} AS {$this->tableName} WHERE 1 AND {$this->tableName}.cat = ".$this->db->quote($this->cat, 'text')." ORDER BY {$this->tableName}.id "; $res = $this->db->queryAll($sql, null, MDB2_FETCHMODE_ASSOC, true); return $this->getSubElem($res, $field); } function initFromForm(&$frm) { $files = array(); $settings = $this->getList4Grid(); foreach ($settings['list'] as $setting) { $name = $setting['name']; switch ($setting['type']){ case 'file': $files[$name] = $frm->getElementValue($name); break; } } $this->initFromArray($frm->exportValues(), $files); return true; } function initFromArray($data, $files) { $settings = $this->getList4Grid(); foreach ($settings['list'] as $setting) { $name = $setting['name']; switch ($setting['type']){ case 'date': $data[$name] = $data[$name]['Y'].'-'.$data[$name]['M'].'-'.$data[$name]['d']; break; } } parent::initFromArray($data, $files); return true; } function update($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $data = $this->_data; unset($data['id']); $this->_initTable(); $settings = $this->getList4Grid(); foreach ($settings['list'] as $setting) { $name = $setting['name']; switch ($setting['type']){ case 'header': // нічого не робимо break; case 'file': if (is_uploaded_file($this->_files[$name]['tmp_name'])){ $this->_initFile(); $oldName = $this->getFromDB(0, $name); $this->id = $setting['id']; $this->handleFile('value', $this->_files[$name]); $this->file->delete( $oldName); } break; default: $this->table->update(array('value' => $data[$name]), 'name = ' . $this->db->quote($name)); } } return true; } function _getOrder4Grid($order_by = '') { $order_by = " ORDER BY {$this->tableName}.id"; return $order_by; } function getAdminEmails($var = 'admin_email') { $emails = preg_replace('/[\r\n]+/',' ', Settings::get($var)); $arrEmails = split('[, ;]', $emails); if (!is_array($arrEmails) || empty($arrEmails)) { return false; } foreach ($arrEmails as $k=>$v) { if (!strlen(trim($v, ',; '))) unset($arrEmails[$k]); } $arrEmails = array_unique($arrEmails); return $arrEmails; } }