0)
{
// Add option for userlog
$cacheArray['admins'] = ADD_OPTION_LINES("admins", "id", "login", "", "email");
$SW = 2; $rowNameS = "";
foreach ($_POST['sel'] as $template => $sel)
{
// First of all load data from DB
$result = SQL_QUERY_ESC("SELECT admin_id, id FROM "._MYSQL_PREFIX."_admins_mails WHERE mail_template='%s' ORDER BY id",
array($template), __FILE__, __LINE__);
$OUT = ""; $aid = 0; $aid2 = 0;
while (list($aid, $id) = SQL_FETCHROW($result))
{
$OUT .= "
\n";
$aid2 = $aid; $id2 = $id;
}
// Free memory
SQL_FREERESULT($result);
$content = array(
'sw' => $SW,
'id' => $id,
'id2' => $id2,
'tpl' => $template,
'admins' => $cacheArray['admins']
);
if ($aid2 > 0)
{
// Add form for an additional admin
$OUT .= LOAD_TEMPLATE("admin_admins_mails_edit_form", true, $content);
}
// Save full rendered content
$content['content'] = $OUT;
// Start outputing line
$rowNameS .= LOAD_TEMPLATE("admin_admins_mails_edit_row", true, $content);
$SW = 3 - $SW;
}
define('__ADMINS_ROWS', $rowNameS);
// Edit checked entries
LOAD_TEMPLATE("admin_admins_mails_edit");
}
else
{
// Nothing selected
LOAD_TEMPLATE("admin_settings_saved", false, ADMINS_NO_MAIL_CHECKED);
}
}
else
{
// Load all assigned mails
$result = SQL_QUERY("SELECT DISTINCT m.id, m.admin_id, a.login, m.mail_template
FROM "._MYSQL_PREFIX."_admins_mails AS m
LEFT JOIN "._MYSQL_PREFIX."_admins AS a
ON m.admin_id=a.id
WHERE (m.admin_id=a.id OR m.admin_id < 1) AND m.mail_template != ''
ORDER BY m.admin_id, m.mail_template", __FILE__, __LINE__);
if (SQL_NUMROWS($result) > 0)
{
// Shall I change entries?
if (isset($_POST['change']))
{
// Ok, update database
foreach ($_POST['admin_id'] as $id => $aid)
{
// Secure IDs
$id = bigintval($id);
$aid = bigintval($aid);
// Update entry
$result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_admins_mails SET admin_id=%s WHERE id=%s ORDER BY id LIMIT 1",
array($aid, $id), __FILE__, __LINE__);
if (($aid < 1) && (!empty($_POST['template'][$id])))
{
// Remove any other admin entries
$result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_admins_mails WHERE mail_template='%s' AND id != '%s'",
array($_POST['template'][$id], $id), __FILE__, __LINE__);
}
if ($_POST['admin_new'][$_POST['template'][$id]] > 0)
{
// Add new admin
$result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_admins_mails (admin_id, mail_template) VALUES ('%s','%s')",
array($aid, $_POST['template'][$id]), __FILE__, __LINE__);
}
}
// Query again...
$result = SQL_QUERY("SELECT DISTINCT m.id, m.admin_id, a.login, m.mail_template FROM "._MYSQL_PREFIX."_admins_mails AS m, "._MYSQL_PREFIX."_admins AS a WHERE m.admin_id=a.id OR m.admin_id < 1 ORDER BY m.admin_id", __FILE__, __LINE__);
}
// List found entries
$SW = 2; $OUT = "";
while(list($id, $aid, $admin, $templ) = SQL_FETCHROW($result))
{
if ($aid > 0)
{
// Admin assigned
$admin_link = "".$admin."";
}
elseif ($aid == 0)
{
// All admins
$admin_link = "".ADMINS_ALL_ADMINS."";
}
elseif (($aid == -1) && (EXT_IS_ACTIVE("usrlog")))
{
// To userlog
$admin_link = "".ADMINS_TO_USERLOG."";
}
$content = array(
'sw' => $SW,
'tpl' => $templ,
'alnk' => $admin_link
);
// Load row template
$OUT .= LOAD_TEMPLATE("admin_admins_mails_list_row", true, $content);
$SW = 3 - $SW;
}
// Free result
SQL_FREERESULT($result);
define('__MAILS_ROWS', $OUT);
// Load template
LOAD_TEMPLATE("admin_admins_mails_list");
}
else
{
// No entries found
LOAD_TEMPLATE("admin_settings_saved", false, ADMINS_MAILS_NO_ENTRIES);
}
}
//
?>