<?php
/**
 * $Source: /home/cvs/nukescripts/admin/modules/promotion/MainPromotion.php,v $
 * $Revision: 1.0.0-1 $
 * $Author: cyril $
 * $Date: 2007/01/17 11:26:34 $
 */
/************************************************************************/
/* 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 (!is_admin($admin)) { redirect_url("".$admin_file.".php"); }
if (!is_user($user)) { redirect_url("".$admin_file.".php"); }

 incoh();
 Max_OpenTable();
 echo "<center><a href='".$admin_file.".php?op=promotion'><font class=\"option\"><b>" . _TITLEPROMO . "</b></font></a></center><br />"
     ."<table border=\"1\" align=\"center\" width='90%'>"
     ."<tr><th>"._NAME."</th><th>"._LANGUAGE."</th><th>"._FUNCTIONS."</th><th>"._FUNCTIONS."</th><th>"._FUNCTIONS."</th></tr>";
 $result = $db->sql_query("SELECT `aid`, `name`, `admlanguage` FROM `".TABLE_AUTHORS."`");
 while ($row = $db->sql_fetchrow($result)) {
 $a_aid       = stripslashes($row['aid']);
 $name        = stripslashes($row['name']);
 $admlanguage = $db->XMFlang($row['admlanguage']);
 $a_aid       = substr("$a_aid", 0,25);
 $name        = substr("$name", 0,25);
 echo "<tr><td align=\"center\">$a_aid</td>";

 if ($admlanguage == "") {
 	$admlanguage = "" . _ALL . "";
 }

 echo "<td align='center'>$admlanguage</td>";
 echo "<td align='center'><a href=\"".$admin_file.".php?op=modifypromotion&amp;chng_aid=$a_aid\">" . _MODIFYINFO . "</a></td>";
 if($name=="God") {
 	echo "<td align='center'>" . _MAINACCOUNT . "</td>";
 } else {
 	echo "<td align='center'><a href=\"".$admin_file.".php?op=delpromotion&amp;del_aid=$a_aid\">" . _DELAUTHOR . "</a></td>";
	}
 if($name=="God") {
 	echo "<td align='center'><a href=\"".$admin_file.".php?op=downgradegod&amp;a_aid=$a_aid\">"._ADMINGOD_DOWNGRADE."</a></td>";
 } else {
 	echo "<td align='center'><a href=\"".$admin_file.".php?op=upgradegod&amp;a_aid=$a_aid\">"._ADMINGOD_UPGRADE."</a></td></tr>";
 }

}
 echo "</table>";

 echo "<form name=\"change\" action=\"".$admin_file.".php?op=promotion\" method=\"post\">"
 . "<center><table border=\"0\" width=\"80%\">"
 . "<tr>"
 . "<td align=\"center\"><br /><select name=\"promotion_id\" onChange=\"javascript:document.change.submit()\">"
 . "<option value=0>" ._CHOIX_USER_PROMO."</option>";
  $result = $db->sql_query("SELECT * FROM `".TABLE_USERS."` ORDER BY `username`");
  while ($row = $db->sql_fetchrow($result)) {
  $user_id  = $db->XMFnum($row['user_id']);
  $username = stripslashes($row['username']);
  $result2  = $db->sql_query("SELECT `aid` FROM `".TABLE_AUTHORS."` WHERE `aid`='$username'");
  $num      = $db->sql_numrows($result2);

  if(isset($_POST['promotion_id']) && ($_POST['promotion_id']==$user_id))
  {$sel = "selected ";}else{$sel = "";}


  if(!$num){
  	$Username = stripslashes( $row['username'] );
  	$view = "<option $sel value=\"$user_id\">$Username</option>\n";
  } else {
  	$view = "";
  }

  echo "$view";
  }
  echo "</select></td></tr></table></form>";
  Max_CloseTable();
  br('1');


  if(isset($_POST['promotion_id']) && $_POST['promotion_id'] > 0){
  $id_promo = stripslashes( $_POST['promotion_id'] );
  list($uname, $rname, $email, $site, $upass) = $db->sql_fetchrow($db->sql_query("SELECT `username`, `name`, `user_email`, `user_website`, `user_password` FROM `".TABLE_USERS."` WHERE `user_id`='$id_promo'"));
  Max_OpenTable();
  echo "<center><table align='center' border='0' cellpadding='2' cellspacing='2'>\n";
  echo "<form action=".$admin_file.".php method='post'>\n";
  echo "<tr><td><table border='0'>";
  echo "<tr><td bgcolor='$bgcolor2'>"._NAME.": <b>$rname</b> <input type=\"hidden\" name=\"add_name\" value=\"$rname\"></td></tr>";
  echo "<tr><td bgcolor='$bgcolor2'>"._NICKNAME.": <b>$uname</b> <input type=\"hidden\" name=\"add_aid\" value=\"$uname\"></td></tr>"
  ."<tr><td>" . _EMAIL . ":</td>"
  ."<td colspan=\"3\"><input type=\"text\" name=\"add_email\" value=\"$email\" size=\"30\" maxlength=\"60\"></td></tr>"
  ."<tr><td>" . _URL . ":</td>"
  ."<td colspan=\"3\"><input type=\"text\" name=\"add_url\" value=\"$site\" size=\"30\" maxlength=\"60\"></td></tr>";
  if ($multilingual == 1) {
  echo "<tr><td>" . _LANGUAGE . ":</td><td colspan=\"3\">"
  ."<select name=\"add_admlanguage\">";
  $handle=opendir('language');
  while ($file = readdir($handle)) {
  if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
  $langFound = $matches[1];
  $languageslist .= "$langFound ";
				}
			}
  closedir($handle);
			$languageslist = explode(" ", $languageslist);
			sort($languageslist);
			for ($i=0; $i < sizeof($languageslist); $i++) {
				if($languageslist[$i]!="") {
					echo "<option value=\"$languageslist[$i]\" ";
					if($languageslist[$i]==$language) echo "selected";
					echo ">".ucfirst($languageslist[$i])."</option>\n";
				}
			}
			echo "<option value=\"\">" . _ALL . "</option></select></td></tr>";
		} else {
			echo "<input type=\"hidden\" name=\"add_admlanguage\" value=\"\">";
		}
	   echo "<tr><td>" . _PERMISSIONS . ":</td>";
		$result = $db->sql_query("SELECT `mid`, `title` FROM `".TABLE_MODULES."` ORDER BY `title` ASC");
		while ($row = $db->sql_fetchrow($result)) {
			$title = ereg_replace("_", " ", $row[title]);
			if (file_exists("modules/$row[title]/admin/index.php") AND file_exists("modules/$row[title]/admin/links.php") AND file_exists("modules/$row[title]/admin/case.php")) {
				echo "<td><input type=\"checkbox\" name=\"auth_modules[]\" value=\"$row[mid]\"> $title</td>";
				if ($a == 2) {
					echo "</tr><tr><td>&nbsp;</td>";
					$a = 0;
				} else {
					$a++;
				}
			}
		}
		echo "</tr><tr><td>&nbsp;</td>";
		echo "</tr><tr><td>&nbsp;</td>"
		."<td><input type=\"checkbox\" name=\"add_radminsuper\" value=\"1\"> <b>" . _SUPERUSER . "</b></td>"
		."</tr><tr><td>&nbsp;</td>"
		."<td colspan=\"3\"><font class=\"tiny\"><i>" . _SUPERWARNING . "</i></font></td></tr>"
        ."<input type=\"hidden\" name=\"add_pwd\" value=\"$upass\">"
		."<input type=\"hidden\" name=\"op\" value=\"promotion_save\">"
		."<tr><td><input type=\"submit\" value=\"" . _ADDAUTHOR2 . "\"></td></tr>";
	echo "</table></form></td></tr>";
    echo "</form>\n";
    echo "</table></center>\n";
	Max_CloseTable();
    }
    incof();

}
}else {
	echo "Access Denied";
}