/** * AlternC's standard function called when a user is created * This sends an email if configured through the interface. * * @global m_err $err * @global int $cuid * @global string $L_FQDN * @global string $L_HOSTING * @return boolean */ function hook_admin_add_member() { global $err, $cuid, $L_FQDN, $L_HOSTING; $dest = variable_get('new_email', '0', 'An email will be sent to this address when new accounts are created if set.', array('desc' => 'Enabled', 'type' => 'boolean')); if (!$dest) { return false; } $db = new DB_System(); if (!$db->query("SELECT m.*, parent.login as parentlogin FROM membres m LEFT JOIN membres parent ON parent.uid=m.creator WHERE m.uid='{$cuid}'")) { $err->raise("admin", sprintf(_("query failed: %s "), $db->Error)); return false; } if ($db->next_record()) { // TODO: put that string into gettext ! $mail = <<<EOF A new AlternC account was created on %fqdn by %creator. Account details --------------- login: %login (%uid) email: %mail createor: %creator (%cuid) can change password: %canpass type: %type notes: %notes EOF; $mail = strtr($mail, array('%fqdn' => $L_FQDN, '%creator' => $db->Record['parentlogin'], '%uid' => $db->Record['uid'], '%login' => $db->Record['login'], '%mail' => $db->Record['mail'], '%cuid' => $db->Record['creator'], '%canpass' => $db->Record['canpass'], '%type' => $db->Record['type'], '%notes' => $db->Record['notes'])); $subject = sprintf(_("New account %s from %s on %s"), $db->Record['login'], $db->Record['parentlogin'], $L_HOSTING); if (mail($dest, $subject, $mail, "From: postmaster@{$L_FQDN}")) { //sprintf(_("Email successfully sent to %s"), $dest); return true; } else { $err->raise("admin", sprintf(_("Cannot send email to %s"), $dest)); return false; } } else { $err->raise("admin", sprintf(_("Query failed: %s"), $db->Error)); return false; } }
/** * This function is called on each class when a domain name is uninstalled * @param string $dom the domain to uninstall */ function alternc_del_domain($dom) { global $err, $cuid; $err->log("aws", "alternc_del_domain", $dom); $db = new DB_System(); $db->query("SELECT id,hostname FROM aws WHERE uid='{$cuid}' AND (hostname='{$dom}' OR hostname like '%.{$dom}')"); $t = array(); while ($db->next_record()) { $t[] = array($db->f("hostname"), $db->f("id")); } foreach ($t as $i) { $db->query("DELETE FROM aws WHERE uid='{$cuid}' AND hostname='" . $i[0] . "';"); $db->query("DELETE FROM aws_access WHERE uid='{$cuid}' AND id='" . $i[1] . "';"); $this->_delconf($i[0]); } return $this->_createhtpasswd(); }