Rewrote some parts:
[mailer.git] / inc / extensions / ext-admins.php
index 598516e96c3382b5cc301a08529d31d2f0eb0293..943f472bc63cdfdd26f04490cfccd050ddbfba78 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 04/11/2004 *
- * ================                             Last change: 10/29/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 04/11/2004 *
+ * ===================                          Last change: 10/29/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : ext-admins.php                                   *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Admin-Accountsverwaltung                         *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
+       die();
+} // END - if
 
 // Version of this extension
-$EXT_VERSION = "0.7.1";
-
-// Auto-set extension version
-if (empty($EXT_VER)) $EXT_VER = $EXT_VERSION;
-
-// Version history array (add more with , "0.1" and so on)
-$EXT_VER_HISTORY = array("0.0", "0.1", "0.2", "0.3", "0.3.1", "0.4.0", "0.4.1", "0.4.2", "0.4.3", "0.4.4", "0.4.5", "0.4.6", "0.4.7", "0.4.8", "0.4.9", "0.5.0", "0.5.1", "0.5.2", "0.5.3", "0.5.4", "0.5.5", "0.5.6", "0.5.7", "0.5.8", "0.5.9", "0.6.0", "0.6.1", "0.6.2", "0.6.3", "0.6.4", "0.6.5", "0.6.6", "0.6.7", "0.6.8", "0.6.9", "0.7.0", "0.7.1");
-
-switch ($EXT_LOAD_MODE)
-{
-case "register": // Do stuff when installation is running (modules.php?module=admin&action=login is called)
-       // SQL commands to run
-       $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('admins', NULL, 'Admin-Management','Administratoren anlegen, l&ouml;schen oder Passwort/E-Mail Adresse &auml;ndern.','1')";
-       $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('admins','admins_add','Admin hinzuf&uuml;gen','Neuen Admin-Account anlegen','0')";
-       $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('admins','admins_edit','Admin-Account &auml;ndern','Bestehende Admin-Accounts bearbeiten: E-Mail-Adresse, Passwort und/oder Login-Name &auml;ndern.','1')";
-       break;
-
-case "remove": // Do stuff when removing extension
-       // SQL commands to run
-       $SQLs[] = "DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_admin_menu` WHERE action='admins' LIMIT 6";
-       $SQLs[] = "DROP TABLE IF EXISTS "._MYSQL_PREFIX."_admins_acls";
-       $SQLs[] = "DROP TABLE IF EXISTS "._MYSQL_PREFIX."_admins_mails";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_admins DROP default_acl";
-
-       // Remove filters
-       UNREGISTER_FILTER('sql_admin_extra_data', 'ADD_EXTRA_SQL_DATA', true, $dry_run);
-       break;
-
-case "activate": // Do stuff when admin activates this extension
-       // SQL commands to run
-       $SQLs[] = "";
-       break;
-
-case "deactivate": // Do stuff when admin deactivates this extension
-       // SQL commands to run
-       $SQLs[] = "";
-       break;
-
-case "update": // Update an extension
-       switch ($EXT_VER)
-       {
-       case "0.2": // SQL queries for v0.2
-               $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('admins','admins_contact','Admin kontaktieren','Kontaktiert einen Admin per Mail oder Nachricht (nur wenn messaging-Erweiterung installiert ist).','2')";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "F&uuml;gt den Men&uuml;punkt &quot;Admin kontaktieren&quot; hinzu.";
-               break;
-
-       case "0.3": // SQL queries for v0.3
-               // Add admin menu
-               $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('admins','config_admins','ACL einstellen','Richten Sie Zugriffskontrollzeilen f&uuml;r jeden Admin individuell ein, um ihm nur bestimmte Bereiche des Admin-Bereiches zug&auml;nglich zu machen oder zu sperren.','4')";
-
-               // Which is the default setting when you create a new admin login?
-               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD admins_default_acl ENUM('deny','allow') NOT NULL DEFAULT 'deny'";
-
-               // Default is deny everything
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_admins ADD default_acl ENUM('deny','allow') NOT NULL DEFAULT 'deny'";
-
-               // But allow current admin everything (THIS SHALL BE YOU!)
-               $SQLs[] = "UPDATE "._MYSQL_PREFIX."_admins SET default_acl='allow' WHERE login='".get_session('admin_login')."' LIMIT 1";
-               $SQLs[] = "DROP TABLE IF EXISTS "._MYSQL_PREFIX."_admins_acls";
-               $SQLs[] = "CREATE TABLE "._MYSQL_PREFIX."_admins_acls (
-id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-admin_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-action_menu VARCHAR(255) NOT NULL DEFAULT '',
-what_menu VARCHAR(255) NOT NULL DEFAULT '',
-access_mode ENUM('deny','allow') NOT NULL DEFAULT 'deny',
-KEY (admin_id),
-PRIMARY KEY (id)
-) TYPE=MyISAM";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Sogn. ACLs werden hinzugef&uuml;gt: <strong>A</strong>ccess <strong>C</strong>ontrol <strong>L</strong>ines sind zu deutsch Zugriffkontrollzeilen, mit denen Sie einstellen k&ouml;nnen, was welcher Admin machen darf oder nicht.";
-               break;
-
-       case "0.3.1": // SQL queries for v0.3.1
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_admins_acls MODIFY id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT";
-               break;
-
-       case "0.4.0": // SQL queries for v0.4.0
-               $SQLs[] = "DROP TABLE IF EXISTS "._MYSQL_PREFIX."_admins_mails";
-               $SQLs[] = "CREATE TABLE "._MYSQL_PREFIX."_admins_mails (
-id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-admin_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-mail_template VARCHAR(255) NOT NULL,
-KEY (admin_id),
-PRIMARY KEY (id)
-) TYPE=MyISAM";
-               $SQLs[] = "INSERT INTO  `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('admins','admins_mails','Admin-Mails','Stellen Sie hier ein, welcher Admin welche Mail erhalten soll. Sie k&ouml;nnen dies (derzeit) jedoch erst, wenn einmal die Mail versendet wurde!','5')";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Kontrollieren Sie, welche Mails welcher Admin oder alle (admin_id=0) bekommen soll oder im UserLog (admin_id=-1) verzeichnet werden soll. Standartm&auml;ssig wird weiter an alle versendet.";
-               break;
-
-       case "0.4.1": // SQL queries for v0.4.1
-               $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_admins_mails WHERE mail_template LIKE '% %'";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Admins-Mails-Tabelle geleert.";
-
-       case "0.4.4": // SQL queries for v0.4.4
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "&amp;admin= in &amp;amp;admin= umgewandelt.";
-               break;
-
-       case "0.4.5": // SQL queries for v0.4.5
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Vorbereitet auf Cache-System";
-               break;
-
-       case "0.4.6": // SQL queries for v0.4.6
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Problem mit cache-Erweiterung gefixt. Der Admin-Bereich war permanent gesperrt.";
-               break;
-
-       case "0.4.7": // SQL queries for v0.4.7
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Es wurde die Zeitmarke der Cache-Datei admins.cache mit ber&uuml;cksichtigt.";
-               break;
-
-       case "0.4.8": // SQL queries for v0.4.8
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.";
-               break;
-
-       case "0.4.9": // SQL queries for v0.4.9
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.";
-               break;
+setThisExtensionVersion('0.7.9');
 
-       case "0.5.0": // SQL queries for v0.5.0
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.";
-               break;
-
-       case "0.5.1": // SQL queries for v0.5.1
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Cache wird endlich gel&oumlscht, wenn Admin entfernt wird.";
-               break;
-
-       case "0.5.2": // SQL queries for v0.5.2
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "L&ouml;schen von Admin-Accounts repariert und HTML-Code ausgelagert in Templates.";
-               break;
-
-       case "0.5.3": // SQL queries for v0.5.3
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Seit <a href=\"#\">Patch 340</a> &uuml;berfl&uuml;ssige HTML-Tags entfernt.";
-               break;
-
-       case "0.5.4": // SQL queries for v0.5.4
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "IP-Nummer und Browserbezeichnung wird in Admin-Mails eingesetzt.";
-               break;
-
-       case "0.5.5": // SQL queries for v0.5.5
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Men&uuml;punkt Admin-Mails korregiert: SQL-Anweisung war fehlerhaft; und HTML-Code in Templates ausgelagert.";
-               break;
-
-       case "0.5.6": // SQL queries for v0.5.6
-               $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_admin_menu` SET what='admins_contct' WHERE what='admins_contact' LIMIT 1";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Namenskonflikt zwischen den Erweiterungen <strong>admins</strong> und (kommender) <strong>contact</strong>.";
-               break;
-
-       case "0.5.7": // SQL queries for v0.5.7
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Links wegen <strong>what=admins_contct</strong> ge&auml;ndert.";
-               break;
-
-       case "0.5.8": // SQL queries for v0.5.8
-               $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_admin_menu` SET what='admins_contct' WHERE what='admins_contact' LIMIT 1";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Ein Punkt in der Versionsnummernliste verhinderte das 0.5.6-Update.";
-               break;
-
-       case "0.5.9": // SQL queries for v0.5.9
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Sicherheitsupdate: SQL-Anweisungen gesch&uuml;tzt.";
-               break;
-
-       case "0.6.0": // SQL queries for v0.6.0
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Link in &quot;ACL Einstellen&quot; zum Admin-Kontaktformular korregiert.";
-               break;
+// Version history array (add more with , '0.0.1' and so on)
+setExtensionVersionHistory(array('0.0.0', '0.1.0', '0.2.0', '0.3.0', '0.3.1', '0.4.0', '0.4.1', '0.4.2', '0.4.3', '0.4.4', '0.4.5', '0.4.6', '0.4.7', '0.4.8', '0.4.9', '0.5.0', '0.5.1', '0.5.2', '0.5.3', '0.5.4', '0.5.5', '0.5.6', '0.5.7', '0.5.8', '0.5.9', '0.6.0', '0.6.1', '0.6.2', '0.6.3', '0.6.4', '0.6.5', '0.6.6', '0.6.7', '0.6.8', '0.6.9', '0.7.0', '0.7.1', '0.7.2', '0.7.3', '0.7.4', '0.7.5', '0.7.6', '0.7.7', '0.7.8', '0.7.9'));
 
-       case "0.6.1": // SQL queries for v0.6.1
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Speichern von Admin-Accounts klappt wieder.";
-               break;
+// Keep this extension always active!
+setExtensionAlwaysActive('Y');
 
-       case "0.6.2": // SQL queries for v0.6.2
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Bitte verschieben Sie die admins-Templates (Ordner: {!PATH!}/templates/de/emails/) in den neuen Order admins!";
+switch (getExtensionMode()) {
+       case 'setup': // Do stuff when installation is running
+               // SQL commands to run
+               addAdminMenuSql('admins', NULL, 'Admin-Management','Administratoren anlegen, l&ouml;schen oder Passwort/E-Mail Adresse &auml;ndern.',1);
+               addAdminMenuSql('admins','admins_add','Admin hinzuf&uuml;gen','Neuen Admin-Account anlegen',0);
+               addAdminMenuSql('admins','admins_edit','Admin-Account &auml;ndern','Bestehende Admin-Accounts bearbeiten: E-Mail-Adresse, Passwort und/oder Login-Name &auml;ndern.',1);
                break;
 
-       case "0.6.3": // SQL queries for v0.6.3
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Abspeichern von Einstellungen repariert.";
-               break;
+       case 'remove': // Do stuff when removing extension
+               // SQL commands to run
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='admins'");
+               addDropTableSql('admins_acls');
+               addDropTableSql('admins_mails');
+               addExtensionDropTableColumnSql('admins', 'default_acl');
 
-       case "0.6.4": // SQL queries for v0.6.4
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Problem mit der Rechtevererbung beseitigt: Geben Sie nun ein Hauptmen&uuml; frei (Allow), dann kann der Admin auch die Untermen&uuml;s erreichen. Zudem k&ouml;nnen Sie gezielte Untermen&uuml;s im freigegeben Hauptmen&uuml; dennoch sperren.";
+               // Remove filters
+               unregisterFilter(__FILE__, __LINE__, 'sql_admin_extra_data', 'ADD_EXTRA_SQL_DATA', TRUE, isExtensionDryRun());
+               unregisterFilter(__FILE__, __LINE__, 'do_admin_login_done', 'RESET_ADMINS_LOGIN_FAILURES', TRUE, isExtensionDryRun());
+               unregisterFilter(__FILE__, __LINE__, 'do_admin_login_pass', 'COUNT_ADMINS_LOGIN_FAILURE', TRUE, isExtensionDryRun());
+               unregisterFilter(__FILE__, __LINE__, 'do_admin_login_done', 'REHASH_ADMINS_PASSWORD', TRUE, isExtensionDryRun());
                break;
 
-       case "0.6.5": // SQL queries for v0.6.5
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Sicherheitsupdate f&uuml;r die Include-Befehle.";
+       case 'activate': // Do stuff when admin activates this extension
+               // SQL commands to run
+               addExtensionSql('');
                break;
 
-       case "0.6.6": // SQL queries for v0.5.6
-               $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_admin_menu` SET what='admins_contct' WHERE what='admins_contact' LIMIT 1";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Namenskonflikt zwischen den Erweiterungen <strong>admins</strong> und (kommender) <strong>contact</strong>.";
+       case 'deactivate': // Do stuff when admin deactivates this extension
+               // SQL commands to run
+               addExtensionSql('');
                break;
 
-       case "0.6.7": // SQL queries for v0.6.7
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_admins ADD la_mode ENUM('global','OLD','NEW') NOT NULL DEFAULT 'global'";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Namenskonflikt zwischen den Erweiterungen <strong>admins</strong> und (kommender) <strong>contact</strong>. Beseitigung eines Fehlers <strong>HTTP_POSR_VARS</strong> beim &Auml;ndern von Administratoren.";
+       case 'update': // Update an extension
                break;
 
-       case "0.6.8": // SQL queries for v0.6.8
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "<strong>set_session()</strong> mit @-Zeichen gegen ungewollte Ausgaben abgesichert.";
+       case 'modify': // When the extension got modified
                break;
 
-       case "0.6.9": // SQL queries for v0.6.9
-               $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_admin_menu` SET title = 'Admin-Management' WHERE action = 'admins' AND (what='' OR what IS NULL) LIMIT 1";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Verwaltung nach Management umbenannt.";
+       case 'test': // For testing purposes
                break;
 
-       case "0.7.0": // SQL queries for v0.7.0
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_admins ADD login_failtures BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_admins ADD last_failture TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Fehlgeschlagene Login-Versuche werden nun mitgez&auml;hlt und der letzte vermerkt.";
+       case 'init': // Do stuff when extension is initialized
                break;
 
-       case "0.7.1": // SQL queries for v0.7.1
-               // Update depends on sql_patches
-               $EXT_UPDATE_DEPENDS = "sql_patches";
-
-               // Add filters
-               REGISTER_FILTER('sql_admin_extra_data', 'ADD_EXTRA_SQL_DATA', false, true, $dry_run);
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Filter hinzugef&uuml;gt und ist von <strong>sql_patches</strong> abh&auml;ngig.";
+       default: // Unknown extension mode
+               reportBug(__FILE__, __LINE__, sprintf('Unknown extension mode %s in extension %s detected.', getExtensionMode(), getCurrentExtensionName()));
                break;
-       }
-       break;
-
-case "test": // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
-       break;
-
-default: // Do stuff when extension is loaded
-       break;
-}
-
-// Keep this extension always active!
-$EXT_ALWAYS_ACTIVE = "Y";
+} // END - switch
 
-//
+// [EOF]
 ?>