<?php
/**
 * $Source: /home/cvs/nukescripts/admin/modules/promotion/UpdatePromotion.php,v $
 * $Revision: 1.0.0-1 $
 * $Author: cyril $
 * $Date: 2007/01/08 11:35:06 $
 * Fix Bug 196
 */
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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 */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
	die ("Access Denied");
}
if ($acces == 1) {
if($admintest && $adminsecu)  {

if (!defined('SECUR_MAX')) {
	die ();
}

if (!is_god($admin)) { redirect_url("".$admin_file.".php"); }
if (! defined('ADMIN_ALLOW') ) { redirect_url("".$admin_file.".php"); }
if (! defined('USER_ALLOW') ) { redirect_url("".$admin_file.".php"); }

		$chng_aid  = trim($chng_aid);
		$chng_pwd2 = trim($chng_pwd2);
		if (!($chng_aid && $chng_name && $chng_email)) {
			redirect_url("".$admin_file.".php?op=promotion");
		}
		if ($chng_pwd2 != "") {

		$chng_pwd = md5($chng_pwd2);
		$result = $GLOBALS['db']->sql_query("UPDATE `".TABLE_AUTHORS."` SET `pwd`='$chng_pwd' WHERE `name`='$chng_name'");
			$chng_aid = substr("$chng_aid", 0,25);
			if ($chng_radminsuper == 1) {
				$result = $GLOBALS['db']->sql_query("SELECT `mid`, `admins` FROM `".TABLE_MODULES."`");
				while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
					$admins = explode(",", $row[admins]);
					$adm = "";
					for ($a=0; $a < sizeof($admins); $a++) {
						if ($admins[$a] != "$chng_name" AND $admins[$a] != "") {
							$adm .= "$admins[$a],";
						}
					}
					$GLOBALS['db']->sql_query("UPDATE `".TABLE_MODULES."` SET `admins`='$adm' WHERE `mid`='$row[mid]'");
				}
				$result = $GLOBALS['db']->sql_query("UPDATE `".TABLE_AUTHORS."` SET `aid`='$chng_aid', `email`='$chng_email', `url`='$chng_url', `radminsuper`='$chng_radminsuper', `pwd`='$chng_pwd', `admlanguage`='$chng_admlanguage' WHERE `name`='$chng_name'");
            			$GLOBALS['db']->sql_query("UPDATE `".TABLE_USERS."` SET `user_password`='$chng_pwd' WHERE `username`='$chng_aid'");
				redirect_url("".$admin_file.".php?op=promotion");
			} else {
				if ($chng_name != "God" AND $chng_radminsuper != 0) {
					$result = $GLOBALS['db']->sql_query("UPDATE `".TABLE_AUTHORS."` SET `aid`='$chng_aid', `email`='$chng_email', `url`='$chng_url', `radminsuper`='0', `pwd`='$chng_pwd', `admlanguage`='$chng_admlanguage' WHERE `name`='$chng_name'");
            				$GLOBALS['db']->sql_query("UPDATE `".TABLE_USERS."` SET `user_password`='$chng_pwd' WHERE `username`='$chng_aid'");
				}
				$result = $GLOBALS['db']->sql_query("SELECT `mid`, `admins` FROM `".TABLE_MODULES."`");
				while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
					$admins = explode(",", $row['admins']);
					$adm = "";
					for ($a=0; $a < sizeof($admins); $a++) {
						if ($admins[$a] != "$chng_name" AND $admins[$a] != "") {
							$adm .= "$admins[$a],";
						}
					}
					$GLOBALS['db']->sql_query("UPDATE `".TABLE_AUTHORS."` SET `radminsuper`='$chng_radminsuper' WHERE `name`='$chng_name'");
					$GLOBALS['db']->sql_query("UPDATE `".TABLE_MODULES."` SET `admins`='$adm' WHERE `mid`='$row[mid]'");
				}
				for ($i=0; $i < sizeof($auth_modules); $i++) {
					$row = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `admins` FROM `".TABLE_MODULES."` WHERE `mid`='$auth_modules[$i]'"));
					$admins = explode(",", $row['admins']);
					for ($a=0; $a < sizeof($admins); $a++) {
						if ($admins[$a] == "$chng_name") {
							$dummy = 1;
						}
					}
					if ($dummy != 1) {
						$adm = "$row[admins]$chng_name";
						$GLOBALS['db']->sql_query("UPDATE `".TABLE_MODULES."` SET `admins`='$adm,' WHERE `mid`='$auth_modules[$i]'");
					}
					$dummy = "";
				}
				redirect_url("".$admin_file.".php?op=promotion");
			}
		} else {
			if ($chng_radminsuper == 1) {
				$result = $GLOBALS['db']->sql_query("SELECT `mid`, `admins` FROM `".TABLE_MODULES."`");
				while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
					$admins = explode(",", $row['admins']);
					$adm = "";
					for ($a=0; $a < sizeof($admins); $a++) {
						if ($admins[$a] != "$chng_name" AND $admins[$a] != "") {
							$adm .= "$admins[$a],";
						}
					}
					$GLOBALS['db']->sql_query("UPDATE `".TABLE_MODULES."` SET `admins`='$adm' WHERE `mid`='$row[mid]'");
				}
				$result = $GLOBALS['db']->sql_query("UPDATE `".TABLE_AUTHORS."` SET `aid`='$chng_aid', `email`='$chng_email', `url`='$chng_url', `radminsuper`='$chng_radminsuper', `admlanguage`='$chng_admlanguage' WHERE `name`='$chng_name'");
				redirect_url("".$admin_file.".php?op=promotion");
			} else {
				if ($chng_name != "God" AND $chng_radminsuper != 0) {
					$result = $GLOBALS['db']->sql_query("UPDATE `".TABLE_AUTHORS."` SET `aid`='$chng_aid', `email`='$chng_email', `url`='$chng_url', `radminsuper`='0', `admlanguage`='$chng_admlanguage' WHERE `name`='$chng_name'");
				}
				$result = $GLOBALS['db']->sql_query("SELECT `mid`, `admins` FROM `".TABLE_MODULES."`");
				while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
					$admins = explode(",", $row['admins']);
					$adm = "";
					for ($a=0; $a < sizeof($admins); $a++) {
						if ($admins[$a] != "$chng_name" AND $admins[$a] != "") {
							$adm .= "$admins[$a],";
						}
					}
					$GLOBALS['db']->sql_query("UPDATE `".TABLE_AUTHORS."` SET `radminsuper`='$chng_radminsuper' WHERE `name`='$chng_name'");
					$GLOBALS['db']->sql_query("UPDATE `".TABLE_MODULES."` SET `admins`='$adm' WHERE `mid`='$row[mid]'");
				}
				for ($i=0; $i < sizeof($auth_modules); $i++) {
					$row = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `admins` FROM `".TABLE_MODULES."` WHERE `mid`='$auth_modules[$i]'"));
					$admins = explode(",", $row['admins']);
					for ($a=0; $a < sizeof($admins); $a++) {
						if ($admins[$a] == "$chng_name") {
							$dummy = 1;
						}
					}
					if ($dummy != 1) {
						$adm = "$row[admins]$chng_name";
						$GLOBALS['db']->sql_query("UPDATE `".TABLE_MODULES."` SET `admins`='$adm,' WHERE `mid`='$auth_modules[$i]'");
					}
					$dummy = "";
				}
				redirect_url("".$admin_file.".php?op=promotion");
			}
		}
		if ($adm_aid != $chng_aid) {
			$result2 = $GLOBALS['db']->sql_query("SELECT `sid`, `aid`, `informant` FROM `".TABLE_STORIES."` WHERE `aid`='$adm_aid'");
			while ($row2 = $GLOBALS['db']->sql_fetchrow($result2)) {
				$sid = $GLOBALS['db']->XMFnum($row2['sid']);
				$old_aid = stripslashes($row2['aid']);
				$old_aid = substr("$old_aid", 0,25);
				$informant = stripslashes($row2['informant']);
				$informant = substr("$informant", 0,25);
				if ($old_aid == $informant) {
					$GLOBALS['db']->sql_query("UPDATE `".TABLE_STORIES."` SET `informant`='$chng_aid' WHERE `sid`='$sid'");
				}
				$GLOBALS['db']->sql_query("UPDATE `".TABLE_STORIES."` SET `aid`='$chng_aid' WHERE `sid`='$sid'");
			}
		}


}
}else {
	echo "Access Denied";
}