<?php
class subscribeModel extends modulesModel_compact_02 {
public function __do() {
try {
switch ($this->action) {
case "admin/index.html?do":
require_once(dirname(__FILE__)."../clients/classes/class.client.obj.php");
require_once(dirname(__FILE__)."../clients/classes/class.clients.agregator.php");
$this->data += array(
"level0" => isset($_REQUEST['level'][0]),
"level1" => isset($_REQUEST['level'][1]),
"level2" => isset($_REQUEST['level'][2]),
"subject" => isset($_REQUEST['subject']) ? substr(strip_tags($_REQUEST['subject']), 0, 0xff) : null,
"body" => isset($_REQUEST['body']) ? $_REQUEST['body'] : null
);
$levels = array();
if ($this->data['level0']) { $levels[] = 0; }
if ($this->data['level1']) { $levels[] = 1; }
if ($this->data['level1']) { $levels[] = 2; }
if (!sizeof($levels)) {
throw new Exception("Ошибка. Вы не выбрали ни одной группы пользователей");
}
if (empty($data['subject'])) {
throw new Exception("Ошибка. Вы не указал тему письма");
}
if (empty($data['body'])) {
throw new Exception("Ошибка. Вы не указали тело письма");
}
$clients = new clientsAgregator();
$clients->appendByLevel($this->core->mysql, $levels);
while ($obj = $clients->fetch()) {
if ($obj->unsubscribed) {
continue;
}
$this->core->tempalteEnenginear->assign("obj", $obj);
$this->core->sendEmail(
"{$obj->lastname} {$obj->firstname} {$obj->middlename}",
$obj->email,
$this->core->cfg['mailfrom']['text'],
$this->core->cfg['mailfrom']['email'],
htmlspecialchars($this->data['subject']),
$this->core->tempalteEnenginear->fetch(
$this->core->getModuleTemplatePath($this->moduleName, "emails/email.tpl")
),
true);
}
throw new Exception("OK", 200);
default:
exit("Module ".$this->moduleName.": fatal error: model don't know action: ".$this->action);
}
} catch (Exception $e) {
switch ($e->getCode()) {
case "200":
$this->assignData();
return true;
case "":
case "500":
$this->assignData();
$this->setError($e->getMessage());
return false;
case "404":
$this->core->page404();
exit();
}
}
}
}
?>?>
Все документирована в классах, IDE отладает комплиты и подсказки.