<?php
##############################################################
##In-portal													##
##############################################################
##					      In-portal							##
##					Intechnic Corporation					##
##			   All Rights Reserved, 1998-2002				##
##															##	
##	No portion of this code may be copied, reproduced or	##	
##	   otherwise redistributed without proper written		##
##	  consent of Intechnic Corporation.  Violation will		##
##	   result in revocation of the license and support		##
##	 privileges along maximum prosecution allowed by law.	##
##############################################################

// new startup: begin
define('REL_PATH', 'admin/users');
$relation_level = count( explode('/', REL_PATH) );
define('FULL_PATH', realpath(dirname(__FILE__) . str_repeat('/..', $relation_level) ) );
require_once FULL_PATH.'/kernel/startup.php';
// new startup: end

/* set the destination of the image upload, relative to the root path */
$DestDir = "kernel/images/";

$pathtolocal = $pathtoroot."kernel/";
require_once ($pathtoroot.$admin."/include/elements.php");
require_once ($pathtoroot."kernel/admin/include/navmenu.php");;
require_once($pathtoroot.$admin."/browse/toolbar.php");
require_once($pathtoroot.$admin."/listview/listview.php");

$m = GetModuleArray();
foreach($m as $key=>$value)
{
    $path = $pathtoroot. $value."admin/include/parser.php";
    if(file_exists($path))
    {
      include_once($path);
    }
}

unset($objEditItems);

$objEditItems = new clsUserManager();
$objEditItems->SourceTable = $objSession->GetEditTable("PortalUser");
$objEditItems->EnablePaging = FALSE;
//Multiedit init
$en = (int)$_GET["en"];
$objEditItems->Query_Item("SELECT * FROM ".$objEditItems->SourceTable);
$itemcount=$objEditItems->NumItems();
$c = $objEditItems->GetItemByIndex($en);

unset($objEditItems);

$objEditItems = new clsImageList();
$objEditItems->SourceTable = $objSession->GetEditTable("Images");

if(isset($_POST["itemlist"]))
{
    if(is_array($_POST["itemlist"]))
    {
      $ImageId = $_POST["itemlist"][0];
    }
    else
    { 
      $ImageId = $_POST["itemlist"];
    }
    
    $img = $objEditItems->GetItem($ImageId);
//    print_r($img);
    $action = "m_img_edit";
    $name = $img->Get("Name");
}
else
{
  $img = new clsImage();
  $img->Set("ResourceId",$c->Get("ResourceId"));
  $action = "m_img_add";
  $name = "'New Image'";

}

$envar = "env=" . BuildEnv() . "&en=$en";
$section = 'in-portal:edituser_image';
$ado = &GetADODBConnection();
$charset = GetRegionalOption('Charset');
/* page header */
print <<<END
<html>
<head>
  <title>In-portal</title>
  <meta http-equiv="content-type" content="text/html;charset=$charset">
  <meta http-equiv="Pragma" content="no-cache">
  <script language="JavaScript">
    imagesPath='$imagesURL'+'/';
  </script>
  <script src="$browseURL/common.js"></script>
  <script src="$browseURL/toolbar.js"></script>
  <script src="$browseURL/utility.js"></script>
  <script src="$browseURL/checkboxes.js"></script>
  <script language="JavaScript1.2" src="$browseURL/fw_menu.js"></script>
  <link rel="stylesheet" type="text/css" href="$browseURL/checkboxes.css">
  <link rel="stylesheet" type="text/css" href="$cssURL/style.css">
  <link rel="stylesheet" type="text/css" href="$browseURL/toolbar.css">
END;


$title = GetTitle("la_Text_User", "la_Text_General", $c->Get('PortalUserId'), $c->Get('Login'));//prompt_language("la_Text_Editing")." ".prompt_language("la_Text_User")." '".$c->Get("Login")."' - ".prompt_language("la_Text_Image");
$title .= " '".$name."'";
$objCatToolBar = new clsToolBar();
$objCatToolBar->Add("img_save", "la_Save","#","swap('img_save','toolbar/tool_select_f2.gif');", "swap('img_save', 'toolbar/tool_select.gif');","edit_submit('user','UserEditStatus','".$admin."/users/adduser_images.php',0);",$imagesURL."/toolbar/tool_select.gif");
$objCatToolBar->Add("img_cancel", "la_Cancel","#","swap('img_cancel','toolbar/tool_cancel_f2.gif');", "swap('img_cancel', 'toolbar/tool_cancel.gif');","edit_submit('user','UserEditStatus','".$admin."/users/adduser_images.php',-1);",$imagesURL."/toolbar/tool_cancel.gif");

//echo "<pre>"; print_r($objCatToolBar); echo "</pre>";
int_header($objCatToolBar,NULL,$title);
if ($objSession->GetVariable("HasChanges") == 1) {
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="toolbar">
  <tr>
    <td valign="top">
      <?php int_hint_red(admin_language("la_Warning_Save_Item")); ?>
    </td>
  </tr>
</table>
<?php } ?>  
<TABLE cellSpacing="0" cellPadding="2" width="100%" class="tableborder">
<FORM enctype="multipart/form-data" ID="user" NAME="user" method="POST" ACTION="">
<?php int_subsection_title(prompt_language("la_Text_Image")); ?>
<TR <?php int_table_color(); ?> >
  <TD><?php echo prompt_language("la_prompt_ImageId"); ?></TD>
  <TD><?php if ($img->Get("ImageId") != -1) echo $img->Get("ImageId"); ?></TD>
  <TD></TD>
</TR>

<TR <?php int_table_color(); ?> >
  <TD><SPAN class="text" id="prompt_imgName"><?php echo prompt_language("la_prompt_Name"); ?></SPAN></TD>
  <TD><input type=text NAME="imgName" ValidationType="exists" tabindex="1" size="30" VALUE="<?php echo inp_htmlize($img->parsetag("image_name")); ?>"></TD>
  <TD></TD>
</TR>

<TR <?php int_table_color(); ?> >
  <TD><SPAN class="text" id="prompt_imgAlt"><?php echo prompt_language("la_prompt_AltName"); ?></SPAN></TD>
  <TD><input type=text NAME="imgAlt" ValidationType="exists" size="30" tabindex="2" VALUE="<?php echo inp_htmlize($img->parsetag("image_alt")); ?>"></TD>
  <TD></TD>  
</TR>                                                       

<TR <?php int_table_color(); ?> >
  <TD><?php echo prompt_language("la_prompt_Status"); ?></TD>
  <TD>
    <input type=RADIO NAME="imgEnabled" tabindex="3" <?php if($img->Get("Enabled")==1) echo "CHECKED"; ?> VALUE="1"><?php echo prompt_language("la_Text_Enabled"); ?>
    <input type=RADIO NAME="imgEnabled" tabindex="3" <?php if($img->Get("Enabled")==0) echo "CHECKED"; ?> VALUE="0"><?php echo prompt_language("la_Text_Disabled"); ?>   
  </TD>
  <TD></TD>  
</TR>

<TR <?php int_table_color(); ?> >
    <TD><?php echo prompt_language("la_prompt_Primary"); ?></TD>
    <TD><input type=checkbox NAME="imgDefault" tabindex="4" <?php if($img->Get("DefaultImg")==1) echo "CHECKED"; ?> VALUE="1"></TD>
    <TD></TD>  
</TR>

<TR <?php int_table_color(); ?> >
  <TD><?php echo prompt_language("la_prompt_Priority"); ?></TD>
  <TD><input type=text SIZE="5" NAME="imgPriority" tabindex="5" VALUE="<?php echo $img->Get("Priority"); ?>"></TD>
  <TD></TD>
</TR>


<?php int_subsection_title(prompt_language("la_text_Thumbnail_Image")); ?>

<TR <?php int_table_color(); ?> >
  <TD><?php echo prompt_language("la_prompt_Location"); ?></TD>
  <?php
     if($img->Get("LocalThumb")==1 || strlen($img->Get("LocalThumb"))==0)
     {
     	$local="checked";
     	$remote = "";
     }
     else
     {
     	$remote="checked";
     	$local = "";
     }
  ?>
  <TD>
  <TABLE border=0>
  <tr>
    <TD>
   		<input type="radio" name="imgLocalThumb" tabindex="6" <?php echo $local; ?> VALUE="1"><?php echo prompt_language("la_prompt_upload"); ?>:
   	</td>
   	<td>
   	  <input type=FILE NAME="imgThumbFile" tabindex="7" VALUE=""> <br />
   	</td>
  </tr>
  <tr>
    <td> 		
  		<input type="radio" name="imgLocalThumb" tabindex="6" <?php echo $remote; ?> VALUE="0"> <?php echo prompt_language("la_prompt_remote_url"); ?>:
  	</td> 
  	<td>
  	    <input type=text size=32 NAME="imgThumbUrl" tabindex="8" VALUE="<?php echo $img->Get("ThumbUrl"); ?>"> <br />
  	</td>
  </tr>
  </table>	    
  </TD>
  

  <TD ALIGN="RIGHT">
    <IMG SRC="<?php echo $img->ThumbURL(); ?>">
  </TD>
</TR>

<?php int_subsection_title(prompt_language("la_Text_Full_Size_Image")); ?>

<TR <?php int_table_color(); ?>>     
  <TD><?php echo prompt_language("la_text_Same_As_Thumbnail"); ?></TD>
  <?php
    
    if(($img->Get("SameImages")=="1") || !$img->Get("ImageId") || ($img->Get("ImageId") == "-1"))
    { 
        
    	$checked = "CHECKED";
        $disabled = "DISABLED=\"true\"";        
    }
  ?>
  <TD><input type=checkbox id="imgSameImages" NAME="imgSameImages" tabindex="9" VALUE="1" <?php echo $checked; ?> ONCLICK="enableFullImage(this);"></TD>
  <TD></TD>
</TR>
<TR <?php int_table_color(); ?>> 
  <TD><?php echo prompt_language("la_prompt_Location"); ?></TD>
  <?php
     if($img->Get("LocalImage")==1 || strlen($img->Get("LocalImage"))==0)
     {
     	$local="checked";
     	$remote = "";
     }
     else
     {
     	$remote="checked";
     	$local = "";
     }
  ?>
  <TD>
  <TABLE border=0>
  <tr>
    <TD>
   		<input id="full1" type="radio" name="imgLocalFull" tabindex="10" <?php echo $local; ?> VALUE="1"><?php echo prompt_language("la_prompt_upload"); ?>:
   	</td>
   	<td>
   	  <input type=FILE ID="imgFullFile" NAME="imgFullFile" tabindex="11" VALUE=""> <br />
   	</td>
  </tr>
  <tr>
    <td> 		
  		<input id="full2" type="radio" name="imgLocalFull" tabindex="10" <?php echo $remote; ?> VALUE="0"> <?php echo prompt_language("la_prompt_remote_url"); ?>:
  	</td> 
  	<td>
  	    <input type=text size=32 ID="imgFullUrl"  tabindex="12" NAME="imgFullUrl" VALUE="<?php echo $img->Get("Url"); ?>"> <br />
  	</td>
  </tr>
  </table>	 
  </td> 
  <TD ALIGN="RIGHT">
    <IMG SRC="<?php echo $img->FullURL(); ?>">
  </TD>
</TR>
      <input type=hidden NAME="Action" VALUE="<?php echo $action; ?>">
      <input type="hidden" name="UserEditStatus" VALUE="0">
      <input type="hidden" name="DestDir" VALUE="<?php echo $DestDir; ?>">
      <INPUT TYPE="hidden" NAME="ImageId" VALUE="<?php echo $img->Get("ImageId"); ?>">
      <input TYPE="HIDDEN" NAME="ResourceId" VALUE="<?php echo $c->Get("ResourceId"); ?>">
</FORM>
</TABLE>

<!-- CODE FOR VIEW MENU -->
<form method="post" action="user_groups.php?<?php echo $envar; ?>" name="viewmenu">
<input type="hidden" name="fieldname" value="">
<input type="hidden" name="varvalue" value="">
<input type="hidden" name="varvalue2" value="">
<input type="hidden" name="Action" value="">
</form>
<script language="JavaScript">
  enableFullImage(document.getElementById('imgSameImages'));
  MarkAsRequired(document.getElementById("user"));
</script> 
<!-- END CODE-->
<?php int_footer(); ?>