Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-theme_edit.php
index 15418d191cb147ff6d22b74768d46c1670caee25..e1e60490fe0c846ca50d7c47b8c3ef4a07537380 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 02/12/2004 *
- * ================                             Last change: 02/12/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 02/12/2004 *
+ * ===================                          Last change: 02/12/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-theme_edit.php                              *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  :                                                  *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $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 - 2015 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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!is_admin()))
-{
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
-// Add description as navigation point
-ADD_DESCR("admin", basename(__FILE__));
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+       die();
+} // END - if
 
-global $CurrTheme;
+// Add description as navigation point
+addYouAreHereLink('admin', __FILE__);
 
 // Check for selected themes
-$SEL = 0;
-if (!empty($_POST['sel'])) $SEL = SELECTION_COUNT($_POST['sel']);
-if ($SEL > 0)
-{
-       $OUT = "";
-       foreach ($_POST['sel'] as $id=>$sel)
-       {
-               $SQL = "";
+if (ifPostContainsSelections()) {
+       $OUT = '';
+       foreach (postRequestElement('sel') as $id => $sel) {
+               $sql = '';
                // Shall I de-/activate or delete themes?
-               if (isset($_POST['status']))
-               {
+               if (isPostRequestElementSet('status')) {
                        // Change status
-                       if ($_POST['active'][$id] == 'Y')
-                       {
-                               $SQL = "UPDATE "._MYSQL_PREFIX."_themes SET theme_active='N' WHERE id='".$id."' LIMIT 1";
-                       }
-                        else
-                       {
-                               $SQL = "UPDATE "._MYSQL_PREFIX."_themes SET theme_active='Y' WHERE id='".$id."' LIMIT 1";
+                       if (postRequestElement('active', $id) == 'Y') {
+                               $sql = "UPDATE `{?_MYSQL_PREFIX?}_themes` SET `theme_active`='N' WHERE `id`=%s LIMIT 1";
+                       } else {
+                               $sql = "UPDATE `{?_MYSQL_PREFIX?}_themes` SET `theme_active`='Y' WHERE `id`=%s LIMIT 1";
                        }
-                       $OUT = ADMIN_THEMES_UPDATED;
-               }
-                elseif (isset($_POST['del']))
-               {
+                       $OUT = '{--ADMIN_THEMES_UPDATED--}';
+               } elseif (isFormSent('delete')) {
                        // Delete themes
-                       $SQL = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_themes WHERE id='".$id."' LIMIT 1";
-                       $OUT = ADMIN_THEMES_DELETED;
+                       $sql = "DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_themes` WHERE `id`=%s LIMIT 1";
+                       $OUT = '{--ADMIN_THEMES_DELETED--}';
                }
 
                // Run SQL command?
-               if (!empty($SQL)) $result = SQL_QUERY($SQL, __FILE__, __LINE__);
-       }
+               if (!empty($sql)) {
+                       // Run it
+                       $result = sqlQueryEscaped($sql, array(bigintval($id)), __FILE__, __LINE__);
+
+                       // Rebuild cache
+                       rebuildCache('themes', 'themes');
+               } // END - if
+       } // END - foreach
 
        // Output generated?
-       if (empty($OUT)) ADMIN_THEME_NO_OUTPUT;
-} elseif (!empty($_GET['default_theme'])) {
+       if (empty($OUT)) $OUT = '{--ADMIN_THEME_NO_OUTPUT--}';
+} elseif (isGetRequestElementSet('default_theme')) {
+       // Escape string from input
+       $postData['default_theme'] = getRequestElement('default_theme');
+
+       // Set session
+       setMailerTheme($postData['default_theme']);
+
+       // Set it in config and current theme as well
+       setConfigEntry('default_theme', $postData['default_theme']);
+
        // Save theme
-       $POST['default_theme'] = SQL_ESCAPE($_GET['default_theme']);
-       set_session("mxchange_theme", $POST['default_theme'], (time() + 60*60*24*365), COOKIE_PATH);
-       ADMIN_SAVE_SETTINGS($POST);
+       adminSaveSettings($postData);
 }
 
+// Init rows
+$OUT = '';
+
 // Switch to testing mode
-$THEME_MODE = "test";
-
-// Generate output lines for the template
-$OUT = ""; $SW = 2;
-$result = SQL_QUERY("SELECT id, theme_path, theme_active, theme_ver FROM "._MYSQL_PREFIX."_themes ORDER BY theme_path", __FILE__, __LINE__);
-if (SQL_NUMROWS($result) > 0)
-{
-       while(list($id, $unix, $active, $ver) = SQL_FETCHROW($result))
-       {
-               // Load theme in test mode
-               require(PATH."theme/".$unix."/theme.php");
-
-               // Is the loaded theme name != current theme name?
-               $LINK = $unix;
-               if ($unix != $CurrTheme) $LINK = "<A href=\"".URL."/modules.php?module=admin&amp;what=theme_edit&amp;default_theme=".$unix."\" title=\"".ADMIN_SET_AS_NEW_THEME."\">".$unix."</A>";
-
-               // Prepare data for the row template
-               $content = array(
-                       'sw'        => $SW,
-                       'id'        => $id,
-                       'active'    => $active,
-                       'link'      => $LINK,
-                       'name'      => $THEME_NAME,
-                       'is_act'    => TRANSLATE_YESNO($active),
-                       'email'     => "<A href=\"mailto:".$THEME_EMAIL."?Subject=[Theme:] ".$THEME_NAME." (".$unix.")"."\">".$THEME_AUTHOR."</A>",
-                       'url_link'  => DEREFERER($THEME_URL),
-                       'url_title' => $THEME_URL,
-                       'ver'       => $ver,
-               );
-
-               // Load row template and switch color
-               $OUT .= LOAD_TEMPLATE("admin_theme_edit_row", true, $content);
-               $SW = 3 - $SW;
-       }
+$GLOBALS['theme_mode'] = 'test';
+
+$result = sqlQuery("SELECT
+       `id`,
+       `theme_path`,
+       `theme_active`,
+       `theme_ver` AS `theme_version`,
+       `theme_name`
+FROM
+       `{?_MYSQL_PREFIX?}_themes`
+ORDER BY
+       `theme_path` ASC", __FILE__, __LINE__);
+
+if (!ifSqlHasZeroNumRows($result)) {
+       while ($content = sqlFetchArray($result)) {
+               // Is the theme readable?
+               if (isThemeReadable($content['theme_path'])) {
+                       // Load theme in test mode
+                       loadInclude(sprintf('theme/%s/theme.php', $content['theme_path']));
+
+                       // Copy data from theme to content
+                       $content['theme_url'] = $GLOBALS['theme_data']['url'];
+
+                       // Is the loaded theme name != current theme name?
+                       $content['link'] = $content['theme_path'];
+                       if ($content['theme_path'] != getCurrentTheme()) {
+                               $content['link'] = '<a href="{%url=modules.php?module=admin&amp;what=theme_edit&amp;default_theme=' . $content['theme_path'] . '%}" title="{--ADMIN_SET_AS_DEFAULT_THEME--}">' . $content['theme_path'] . '</a>';
+                       } // END - if
+
+                       // Prepare data for the row template
+                       $content['email'] = '<a href="mailto:' . $GLOBALS['theme_data']['email'] . '?Subject=[Theme:] ' . $GLOBALS['theme_data']['name'] . ' (' . $content['theme_path'] . ')\>' . $GLOBALS['theme_data']['author'] . '</a>';
+
+                       // Load row template and switch color
+                       $OUT .= loadTemplate('admin_edit_theme_row', TRUE, $content);
+               } else {
+                       // Not readable
+                       $OUT .= loadTemplate('admin_edit_theme_row_404', TRUE, $content);
+               }
+       } // END - while
 
        // Free memory
-       SQL_FREERESULT($result);
+       sqlFreeResult($result);
+} else {
+       // No themes found???
+       $OUT .= '<tr>
+  <td colspan="7" class="bottom" height="60">
+    ' . displayMessage('{--ADMIN_NO_THEMES_FOUND--}', TRUE) . '
+  </td>
+</tr>';
 }
- else
-{
-               // No themes found???
-       $OUT .= "<TR>
-  <TD colspan=\"7\" class=\"bottom2\" height=\"60\">
-    ".LOAD_TEMPLATE("admin_settings_saved", true, ADMIN_NO_THEMES_FOUND)."
-  </TD>
-</TR>\n";
-}
-
-define('__THEME_LIST', $OUT);
 
 // Load template
-LOAD_TEMPLATE("admin_theme_edit");
+loadTemplate('admin_edit_theme', FALSE, $OUT);
 
-//
+// [EOF]
 ?>