###############################################################################
# BizDesign ImageFolio Lite Edition 4.2 (Four-dot-Two)
###############################################################################
#
#          ##          ###        VERSION       :  4.2
#        ####        ##   ##      RELEASED ON   :  02/15/2007
#      ##  ##              ##     LAST MODIFIED :  02/15/2007
#    ##########          ##       
#          ##   ###    ##         
#          ##   ###  ########     
#
###############################################################################
# Released by BizDesign, Inc.
# written by Dirk Koppers and Greg Raaum of BizDesign
#
# Purchasing :  http://imagefolio.com/purchase/
# Support    :  http://imagefolio.com/support/
# Phone      :  (214) 642-9787
# Email      :  sales@bizdesign.com
###############################################################################
# COPYRIGHT AND LICENSE INFORMATION :
#
# Copyright (c) 1999-2007 BizDesign, Inc. All rights reserved.
#
# Selling or distributing the code for this program without prior written
# consent is expressly forbidden.
#
# One licensed copy of the program may reside on a single server, in use by a
# single domain.  For each installed instance of the program, a separate
# license is required.
#
# Licensed users may alter or modify this software, at their own risk, of
# course.  They may also hire others to modify their own copy of the code, as
# long as the code is not transferred to or retained by the individual who is
# hired (unless he/she is also a license holder). Although license-holders
# may modify the code for their use, modified code may NOT be resold or
# distributed.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BIZDESIGN,
# INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# BizDesign, Inc. is not liable for any conduct associated with image gallery
# activity, nor for any binary media posted using this program, including but
# not imited to images, photographs, movies, and clipart.
#
# The user must assume the entire risk of using the program.  Although this
# program has been thoroughly tested on BizDesign's servers, BizDesign does not
# warrant that it works on all servers and will not be held liable for anything,
# including but not limited to, misusage, error, or loss of data.  ANY
# LIABILITY OF THE SELLER WILL BE LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT
# OR REFUND OF PURCHASE PRICE.  Use at your own risk!
###############################################################################
# Do not modify below this line unless you know what you are doing.
###############################################################################

$ADDNEWADMIN = "active";

#require "admin/init.pl";
if ($using_multiuser_mod) {
   require "$config_directory/users_config.pl";
}


   if (!$is_admin) {
      print "Content-type: text/html\n\n";
      print qq|<html><head><meta http-equiv="refresh" content="0 ;url=$adminurl"></head></html>|;
      exit;
   }


###############################################################################
# STEP ONE
# called if we haven't added a user yet
###############################################################################
sub step_one {

$pagetitle = "Add New Admin";
&get_header;

print qq|

<form method=post action="$imagefolio_url">
<input type=hidden name=admin value="admin">
<input type=hidden name=cgi value="admin_user_setup.pl">
<input type=hidden name=newaction value="adduser">
<input type=hidden name=uid value="$FORM{'uid'}">

<center>


<table border=0 cellspacing=0 cellpadding=0 width="100%" height="100%"><tr>
<td align=center>

<table border=0 cellspacing=0 cellpadding=0 width="100%" bgcolor="#000000"><tr>
<td align=center valign=middle>

<table border=0 cellspacing=1 cellpadding=0 width="100%" bgcolor="#000000">


<tr bgcolor="#ffcc00"><td>

<table border="0" width="100%" cellspacing=0 cellpadding=4>
<tr><td><$admin_big_font><b>Add New Admin</b></font></td>
<td align=right><$admin_big_font><b>Step 1 of 1</b></font></td>
</tr></table></td></tr>

<tr bgcolor="#eeeeee">
<td align=center>


<table border=0 cellspacing=0 cellpadding=10 width="100%"><tr><td align=center>

<table border=0 cellspacing=0 cellpadding=4 width="600"><tr>

<td colspan=3>
<$admin_font>To <b>Add a New Administrator</b> please enter
a username and password combination below.</font><br></td></tr>

<tr><td colspan=3>&nbsp;</td></tr>

<tr><td align=right><$admin_font><b>Username</b></font></td>
<td><input type=text maxlength=50 name="newlogin" size=20></td>
<td nowrap><$admin_small_font>Min 5 characters, no spaces</font></td></tr>

<tr><td colspan=3>&nbsp;</td></tr>

<tr><td colspan=3><$admin_font>A password is
required to login.  To make the administration area more secure, please use
a <b>mixed case combination of at least 6 letters and numbers.<b></font><br></td></tr>

<tr><td colspan=3>&nbsp;</td></tr>

<tr><td align=right><$admin_font><b>Password</b></font></td>
<td><input type=password maxlength=50 name="password" size=10></td>
<td nowrap><$admin_small_font>Min 6 characters</font></td></tr>

<tr><td align=right nowrap><$admin_font><b>Retype Password</b></font></td>
<td><input type=password maxlength=50 name="sec_password" size=10></td>
<td>&nbsp;</td></tr>

<tr><td colspan=3>&nbsp;</td></tr>

<tr><td colspan=3><$admin_font>Your <b>Name and Email Address
are required</b> to personalize your Administrator Account.</font><br></td></tr>

<tr><td colspan=3>&nbsp;</td></tr>

<tr><td align=right><$admin_font><b>First Name</b></font></td>
<td colspan=2><input type=text maxlength=50 name="firstname" size=35></td>
</tr>

<tr><td align=right><$admin_font><b>Last Name</b></font></td>
<td colspan=2><input type=text maxlength=50 name="lastname" size=35></td>
</tr>

<tr><td align=right><$admin_font><b>Email Address</b></font></td>
<td colspan=2><input type=text maxlength=50 name="email" size=35></td>
</tr>

<tr><td colspan=3>&nbsp;</td></tr>

<tr><td colspan=3 align=center><$admin_font>Please set <b>Permissions</b> for this administrator below:<b></font><br></td></tr>

<tr><td colspan=3>&nbsp;</td></tr>

<tr><td colspan=3 align=center>
<table border=0 cellspacing=0 cellpadding=0 width="450" bgcolor="#000000"><tr><td align=center valign=middle>
<table border=0 cellspacing=1 cellpadding=4 width="100%"><tr bgcolor="#ff0000">
<td width="80%"><$admin_font color="#ffffff"><b>Allow this administrator to...</b></font></td>
<td align=center width="10%"><$admin_font color="#ffffff"><b>Yes</b></font></td>
<td align=center width="10%"><$admin_font color="#ffffff"><b>No</b></font></td></tr>

<tr bgcolor="#dddddd">
<td><$admin_font><b>Add IPTC File Info</b> ?</font></td>
<td align=center><input type=radio name="desc_per" value=Yes checked></td>
<td align=center><input type=radio name="desc_per" value=No></td>
</tr>

<tr bgcolor="#ffffff">
<td><$admin_font><b>Upload Media</b> ?</font></td>
<td align=center><input type=radio name="upload_per" value=Yes checked></td>
<td align=center><input type=radio name="upload_per" value=No></td>
</tr>

<tr bgcolor="#dddddd">
<td><$admin_font><b>Add Categories</b> ?</font></td>
<td align=center><input type=radio name="addcat_per" value=Yes checked></td>
<td align=center><input type=radio name="addcat_per" value=No></td>
</tr>

<tr bgcolor="#ffffff">
<td><$admin_font><b>Rename Categories</b> ?</font></td>
<td align=center><input type=radio name="rencat_per" value=Yes checked></td>
<td align=center><input type=radio name="rencat_per" value=No></td>
</tr>

<tr bgcolor="#dddddd">
<td><$admin_font><b>Delete Categories</b> ?</font></td>
<td align=center><input type=radio name="delcat_per" value=Yes checked></td>
<td align=center><input type=radio name="delcat_per" value=No></td>
</tr>

<tr bgcolor="#ffffff">
<td><$admin_font><b>Rebuild the Database/Index</b> ?</font></td>
<td align=center><input type=radio name="build_per" value=Yes checked></td>
<td align=center><input type=radio name="build_per" value=No></td>
</tr>

<tr bgcolor="#dddddd">
<td><$admin_font><b>Add New Administrator/Groups/Users</b> ?</font></td>
<td align=center><input type=radio name="addusr_per" value=Yes checked></td>
<td align=center><input type=radio name="addusr_per" value=No></td>
</tr>

<tr bgcolor="#ffffff">
<td><$admin_font><b>Modify Other Administrators/Groups/Users</b> ?</font></td>
<td align=center><input type=radio name="modusr_per" value=Yes checked></td>
<td align=center><input type=radio name="modusr_per" value=No></td>
</tr>

<tr bgcolor="#dddddd">
<td nowrap><$admin_font><b>Delete Other Administrators/Groups/Users</b> ?</font></td>
<td align=center><input type=radio name="delusr_per" value=Yes checked></td>
<td align=center><input type=radio name="delusr_per" value=No></td>
</tr></table></td></tr></table></td></tr>

<tr><td colspan=3>&nbsp;</td></tr>

<tr><td colspan=3 align=center>
<table border=0 cellspacing=0 cellpadding=0 width="450" bgcolor="#000000"><tr><td align=center valign=middle>
<table border=0 cellspacing=1 cellpadding=4 width="100%"><tr bgcolor="#ff0000">
<td width="80%"><$admin_font color="#ffffff"><b>Use demonstration/tutorial mode ?</b></font></td>
<td align=center width="10%"><$admin_font color="#ffffff"><b>Yes</b></font></td>
<td align=center width="10%"><$admin_font color="#ffffff"><b>No</b></font></td></tr>

<tr bgcolor="#ffffff">
<td><$admin_font>If set to "Yes" then this administrator has access to all functions above but no changes are saved. Useful for showing colleagues/friends or educating employees.</font></td>
<td align=center><input type=radio name="demo_per" value=Yes></td>
<td align=center><input type=radio name="demo_per" value=No checked></td>
</tr>

</table></td></tr></table></td></tr></table>

<br><input type=submit value="Add Administrator"></td></tr></table>

</td></tr></table></td></tr></table>

<br><br>

</font><br>

</td></tr></table>

</center>
</form>
|;

&get_footer;

}

###############################################################################
# STEP TWO
# add a username and password to the database
###############################################################################
sub step_two {

&get_header;
&load_these_values;

   $iflogin =~ s/ //g;
   $plength = length($ifpassword);
   $llength = length($iflogin);


# WE MAKE SURE THAT THIS USERNAME IS AVAILABLE FIRST

   if (-e "$admindb") {
      open (FILE,"$admindb") or &Error("Can't Open $admindb: $!");
      my(@LINES)=<FILE>;
      close(FILE);
      chomp @LINES;
   }

   foreach $line (@LINES) {
      ($username) = split(/\|/, $line);

      if (lc($username) eq lc($iflogin)) {
         print &Error('The Username you requested is already in use by another administrator.');
         exit;
      }
   }


   if    (!$iflogin)                    { print &Error('You must enter a Username.');                      exit; }
   elsif (!$ifemail)                    { print &Error('You must enter an Email Address.');              exit; }
   elsif (!$ifpassword)                 { print &Error('You must enter a Password.');                      exit; }
   elsif (!$ifsec_password)             { print &Error('You must enter the Password twice.');             exit; }
   elsif ($ifsec_password ne $ifpassword) { print &Error('The Passwords do not match.');                    exit; }
   elsif ($plength < 6)               { print &Error('The Password must be at least six characters.');  exit; }
   elsif ($llength < 5)               { print &Error('The Username must be at least five characters.'); exit; }
   elsif (!$iffirstname)                { print &Error('You must enter a First Name.');                 exit; }
   elsif (!$iflastname)                 { print &Error('You must enter a Last Name.');                  exit; }


# BELOW WE CREATE A RANDOM DIGITAL ID FOR THE USER JUST IN CASE WE NEED TO USE IT LATER

   $ifuserid = int(rand(1234567890)) + time;

# HERE WE ENCRYPT THE PLAINTEXT PASSWORD

   require "$libpath/crypt.pl";
   $ifnewpass = &admin_encrypt($ifpassword, $secret_key);

# HERE WE SAVE ALL OF THE PERSONAL INFORMATION FOR THE USER IN THE USER'S DATABASE

   unless ($admin_demo_mode) {
      open (ADMINDB,">>$admindb") or print &Error('Could not open the admin database!');
      if ($useflock) { flock(ADMINDB, 2); }
      print ADMINDB "$iflogin|$ifnewpass|$ifuserid|$ifemail|$iffirstname|$iflastname|";
      print ADMINDB "$ifdesc_per|$ifupload_per|$ifaddcat_per|$ifrencat_per|";
      print ADMINDB "$ifdelcat_per|$ifbuild_per|$ifaddusr_per|$ifmodusr_per|$ifdelusr_per|$ifdemo_per\n";
      if ($useflock) { flock(ADMINDB, 8); }
      close(ADMINDB);
      chmod(0666,"$admindb");
   }



print qq|
<center><font face="Verdana,Arial,Helvetica" size="+1"><b>Administrator Added Successfully!</b></font>

<br><table border=0 cellspacing=0 cellpadding=10 width="600"><tr>

<td><$admin_font>
<b>The ImageFolio Administration Account has been added.  Here is the information you provided. 
Please print or save this information for your records.</b></font><br><pre>

Administrator Authentication Information
==========================================================================
Name:               $iffirstname $iflastname
Email:              $ifemail
Username:           $iflogin
Password:           $ifpassword
Login Location:     <a href="$adminurl">$adminurl</a>


Administrative Permissions
==========================================================================
Add Descriptions:   $ifdesc_per
Upload Media:       $ifupload_per
Add Categories:     $ifaddcat_per
Rename Categories:  $ifrencat_per
Delete Categories   $ifdelcat_per
Build Index:        $ifbuild_per
Add Users:          $ifaddusr_per
Modify Users:       $ifmodusr_per
Delete Users:       $ifdelusr_per
Demo Mode:          $ifdemo_per

</pre><br><br>
</td></tr></table>
|;

&get_footer;

}

###############################################################################
# ERROR
# shows error message if form not filled out correctly
###############################################################################
sub ErrorOLD{


   local ($whoops) = @_;

print qq|
<script language="JavaScript">
<!--
function help(){
window.alert("Help\\n\\nThis error message is displayed either because I was not able to understand your input or your input was incorrect.");
}
//-->
</script>

</head>

<body bgcolor="#ffffff" marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>

<form>

<table border=0 cellspacing=0 cellpadding=0 width="100%" height="100%"><tr><td valign=middle align=center>
<table border=2 cellspacing=0 cellpadding=0 width="350" bgcolor="#000000"><tr><td>
<table border=0 cellspacing=0 cellpadding=3 width="350"><tr bgcolor="000000">
<td nowrap><$admin_font color="#ffffff"><strong>Error!</strong></font></td>
<td align=right nowrap><$admin_font><b><INPUT TYPE="button" VALUE=" ? " onClick="help()">&nbsp;<INPUT TYPE="button" VALUE=" X " onClick="history.go(-1)"></b></font></td></tr>

<tr bgcolor="#eeeeee">
<td colspan=2><table border=0 cellspacing=0 cellpadding=5 width="100%"><tr>
<td><$admin_font><b><font color="#ff0000">$whoops</font></b><br><br>If the button below does not take you back, please use your browser's back button to go back and try again.<br><br></font></td>
</tr></table>

<center><$admin_font><INPUT TYPE="button" VALUE="     OK     " onClick="history.go(-1)"></font></center>

</td></tr></table></td></tr></table></td></tr></table>
</form>
|;

exit;
}

###############################################################################
# LOAD VALUES
# created variables for our form information
###############################################################################
sub load_these_values {
   $ifpassword     = $FORM{'password'};
   $ifsec_password = $FORM{'sec_password'};
   $iffirstname    = $FORM{'firstname'};
   $iflastname     = $FORM{'lastname'};
   $ifemail        = $FORM{'email'};
   $iflogin        = $FORM{'newlogin'};
   $ifdesc_per     = $FORM{'desc_per'};
   $ifupload_per   = $FORM{'upload_per'};
   $ifaddcat_per   = $FORM{'addcat_per'};
   $ifrencat_per   = $FORM{'rencat_per'};
   $ifdelcat_per   = $FORM{'delcat_per'};
   $ifbuild_per    = $FORM{'build_per'};
   $ifaddusr_per   = $FORM{'addusr_per'};
   $ifmodusr_per   = $FORM{'modusr_per'};
   $ifdelusr_per   = $FORM{'delusr_per'};
   $ifdemo_per     = $FORM{'demo_per'};
}

1;