_getDependencyFromDb( $this->db->tblContactGroup, 'id', $this->tableNameDB . '2Group', 'id_mail', 'id_group', $id ); return $this->getSubElem($data, $field); } function _getWhat4Grid($opt = array()) { $sql = '`' . $this->tableName . '`.*, ' . "CONCAT(`{$this->tableName}`.`subject`, ' (', `{$this->tableName}`.`author`, ')') AS `title` "; return $sql; } function getDefaultTemplateId() { $sql = 'SELECT `id` ' . 'FROM `' . $this->db->tblMailTemplate . '` ' . "WHERE `is_default` = 'y' " . 'LIMIT 1'; $res = $this->db->queryOne($sql); $this->isDBError($res); return $res; } function getDefaultTemplate() { $sql = 'SELECT `html` ' . 'FROM `' . $this->db->tblMailTemplate . '` ' . "WHERE `is_default` = 'y' " . 'LIMIT 1'; $res = $this->db->queryOne($sql); $res = $this->tag2BaseUrl($res); $this->isDBError($res); return $res; } function setDefaultTemplate($id_template) { $mailTemplateObj = SiteMap::getObj('Mail/Template/Obj.php', $id_template); $mailTemplateObj->setDefault(); } function getContactEmailsByGroup($id_group) { $id_group = (array)$id_group; $id_group = array_filter($id_group, 'intval'); if (empty($id_group)) { return array(); } $sql = 'SELECT `ContactPerson`.`email` ' . 'FROM `' . $this->db->tblContactPerson . '` AS `ContactPerson` ' . 'JOIN `' . $this->db->tblContactPerson2Group . '` AS `ContactPerson2Group` ' . 'ON `ContactPerson2Group`.`id_person` = `ContactPerson`.`id` ' . 'AND `ContactPerson2Group`.`id_group` IN (' . implode(', ', $id_group) . ') ' . 'JOIN `' . $this->db->tblContactGroup . '` AS `ContactGroup` ' . 'ON `ContactGroup`.`id` = `ContactPerson2Group`.`id_group` ' . 'GROUP BY `ContactPerson`.`id` ' . 'ORDER BY `ContactPerson`.`email` '; $res = $this->db->queryCol($sql); $this->isDBError($res); return $res; } function update($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $this->_initTable(); $this->table->update($this->_data, 'id = '. $this->db->quote($this->id, 'integer') ); $this->updateIds($this->tableNameDB . '2Group', 'id_mail', 'id_group', $this->_data['groups']); $this->handleFiles(); return true; } function writeReport($id_mail, $email, $sendResult) { $time = time(); $data = array( 'id_mail' => intval($id_mail), 'report_date' => date('Y-m-d', $time), 'report_time' => date('H:i:s', $time), 'email' => strval($email), 'success' => ($sendResult) ? 'y' : 'n', ); $this->getTable('MailReport')->insert($data); } function getTable($name) { if (!isset($this->_tables[$name])) { require_once('class/DB/DBTable.php'); $this->_tables[$name] = new DBTable($name); } return $this->_tables[$name]; } function getReport() { $this->initFromDB(); $sql = 'SELECT * ' . 'FROM `' . $this->db->tblMailReport . '` ' . 'WHERE `id_mail` = ' . $this->db->quote($this->id, 'integer') . ' ' . 'ORDER BY `report_date` DESC '; $list = array(); $_list = $this->db->queryAll($sql); foreach ($_list as $li) { $list[$li['report_date']][] = $li; } $result = array(); $result['mail'] = $this->getData(); $result['list'] = $list; return $result; } }