<?php
    session_start();
    include 'function/classes.php';
    //include "../tinyMCE.func.inc.php";
    include("FCKeditor/fckeditor.php") ;
        if(!isset($_SESSION['SESS_MEMBER_ID']) ||
                  (trim($_SESSION['SESS_MEMBER_ID'])==""))
                      {
                          echo "You will need admin rights to view this page";
                          exit();
                      }
       else{
            getArr();
            if (isset($_POST['btnsave'])){
            
            	if ($_GET['tbtype']=='product')
				{
					$logo_path = "logo/";
	            	$logo_path = $logo_path . basename( $_FILES['uploadimage']['name']); 
	            	$ug_path="userguide/";
	            	$ug_path = $ug_path . basename( $_FILES['uploadfile']['name']);
		            if(!move_uploaded_file($_FILES['uploadimage']['tmp_name'], $logo_path))
		            {
					    $saveMsg = "There was an error uploading the logo, please try again!";
					    $saveState=false;
					}
	            	if(!move_uploaded_file($_FILES['uploadfile']['tmp_name'], $ug_path))
	            	{
					    $saveMsg = "There was an error uploading the user guide, please try again!";
					    $saveState=false;
					}
				}
            	if ($_GET['tbtype']=='customsolution')
				{
					$logo_path = "logo/";
	            	$logo_path = $logo_path . basename( $_FILES['uploadimage']['name']); 
	            	$ug_path="userguide/";
	            	$ug_path = $ug_path . basename( $_FILES['uploadfile']['name']);
		            if(!move_uploaded_file($_FILES['uploadimage']['tmp_name'], $logo_path))
		            {
					    $saveMsg = "There was an error uploading the logo, please try again!";
					    $saveState=false;
					}
	            	if(!move_uploaded_file($_FILES['uploadfile']['tmp_name'], $ug_path))
	            	{
					    $saveMsg = "There was an error uploading the user guide, please try again!";
					    $saveState=false;
					}
				}
				
                 $setData="";
                 for($i = 4; $i < $_SESSION['SESS_ARR'][3][$_GET['tbtype']]; $i=$i+3){  
	                    if(($_GET['tbtype']=='product') && ($i==13  || $i==25 || $i==7  || $i==10)) 
	                    {
								if ($i==13)
								{
									if ($_FILES['uploadimage']['tmp_name']!=""){
										$setData = $setData . $_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i] ."='" . $_FILES['uploadimage']['name'] ."',";									
									}
								}
								elseif ($i==25)
								{
									if ($_FILES['uploadfile']['tmp_name']!=""){
										$setData = $setData . $_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i] ."='" . $_FILES['uploadfile']['name'] ."'";
									}
								}
	                    }
	                    elseif(($_GET['tbtype']=='admin') && ($i==10)){
	                    	$setData = $setData . $_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i] ."='" . md5($_POST[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i]]) ."',";
	                    } 
	                    elseif(($_GET['tbtype']=='customsolution') && ($i==16))
	                    {
							
							$setData = $setData . $_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i] ."='" . $str ."',";
	                    }
	                    elseif(($_GET['tbtype']=='customsolution') && ($i==13)) 
	                    {
									if ($_FILES['uploadimage']['tmp_name']!=""){
										$setData = $setData . $_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i] ."='" . $_FILES['uploadimage']['name'] ."',";									
									}
	                    }
	                    else 
                    	{
                    		if (($_POST[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i]])!="")
                    		{
								// remove <font> HTML tags
								if ($i == 22)
								{
									$temp = remove_tag('font',$_POST[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i]]);
									//echo $temp;
								}				
								else
								{
									$temp = $_POST[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i]];
								}
                    			$setData = $setData . $_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i] ."='" . $temp ."',";
								//$setData = $setData . $temp;
								//echo '4 - ' . $i . ' - ' . $setData . '<br>';
                    		}
                    	}
                
                }
                if (substr($setData, -1) == ",")
                {
                	$setData = substr_replace($setData,'',-1,1);
                }
                saveData($_SESSION['SESS_ARR'][0][$_GET['tbtype']], $setData,$_SESSION['SESS_ARR'][2][$_GET['tbtype']][1]."=". $_GET['id'] ."",'update');

                if ($_GET['tbtype']=='product')
				{
					saveData('tb_supported_language', "language_id=". $_POST['language'], "product_id=".$_GET['id'] ,'update');
					saveData('tb_supported_platform', "", "product_id=".$_GET['id'] ,'delete');
					if ($_POST['platform']<>''){
						foreach($_POST['platform'] as $list) {
							saveData('tb_supported_platform', "'".$_GET['id']."','".$list."'", "" ,'new');
						}
					}
				}
                if ($_GET['tbtype']=='customsolution')
				{
				saveData('tb_supported_customplat', "", "product_id=".$_GET['id'] ,'delete');
							if ($_POST['platform']<>''){
								foreach($_POST['platform'] as $list) {
									saveData('tb_supported_customplat', "'".$_GET['id']."','".$list."'", "" ,'new');
								}
							}
				}
				$saveMsg=TRUE;
            }
            $tempTable=getData($_SESSION['SESS_ARR'][1][$_GET['tbtype']],$_SESSION['SESS_ARR'][0][$_GET['tbtype']],$_SESSION['SESS_ARR'][2][$_GET['tbtype']][1]."='" . $_GET['id'] . "'");
       }

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Mobivation</title>
        <meta name="keywords" content="employee list" />
        <meta name="description" content="This page contains employee list" />
        <link href="css/default.css" rel="stylesheet" type="text/css" />
    </head>
<script type="text/javascript" src="../tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

<script type="text/javascript">
tinyMCE.init({
        mode : "specific_textareas",
        editor_selector : "mceEditor"
});
</script>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->

<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: http://www.shiningstar.net -->

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else 
countfield.value = maxlimit - field.value.length;
}
</script>

    <body>
   
        <div id="wrapper">
        <?php include 'include/header.php'; ?>
            <!-- end div#header -->
            <div id="page">
                <div id="content">
                    <div id="welcome">
                        <h1>Edit Data</h1>
                        <!--body-->
                        <form name="frmlogin" enctype="multipart/form-data" method="post" action="<?php echo$_SERVER['PHP_SELF'];?>?tbtype=<?php echo $_GET['tbtype'];?>&id=<?php echo $_GET['id'];?>">
                        <table width="100%" border=0>
                            <?php if ($saveMsg)
                                {
                                    echo "<tr><td colspan='2'></td> <th>Data has been updated<th/></tr>";
                                }
                           
                                for($i = 0; $i< $_SESSION['SESS_ARR'][3][$_GET['tbtype']]; $i=$i+3){
                                    if($_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i]!=""){
                                    if ($i==0)
                                    {
                                       // echo '<td>'.$tempTable[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1]].'</td></tr>';
                                    }
                                    else
                                    {
                                        echo '<tr><td>'.$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i].'</td>';
                                        echo '<td> : </td>';
										if ($_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1] == "product" and $_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1] == "language")
										{	
											$language=getList("language_id","tb_supported_language ","where product_id=".$_GET['id']);
											$num_row=mysql_num_rows($language);
											while($row=mysql_fetch_array($language) ){
												getInputType('selectedit',$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1],$tempTable[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1]],$row['language_id']);}
											}
										elseif ($_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1] == "platform" and ($_GET['tbtype']=='product'))
										{	
											
											$platform=getList("*","tb_platform ","");
											$selectedplatform=getList("platform_id","tb_supported_platform ","where product_id =".$_GET['id']);
											$num_row=mysql_num_rows($platform);
											echo '<td><select multiple name="'.$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1].'[]">';
											$chosen=array(); 
											while($row=mysql_fetch_array($selectedplatform))
											{
												$chosen[]=$row['platform_id'];
											}
											//echo 'aaaaaaaaa'.$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1].$tempTable[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1]].'aaaa';
											getInputType('listboxedit',$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1],$tempTable[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1]],$chosen);
											echo '</select>';
											
										}
										elseif ($_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1] == "platform" and ($_GET['tbtype']=='customsolution'))
										{	
											
											$platform=getList("*","tb_platform ","");
											$selectedplatform=getList("platform_id","tb_supported_customplat ","where product_id =".$_GET['id']);
											$num_row=mysql_num_rows($platform);
											echo '<td><select multiple name="'.$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1].'[]">';
											$chosen=array(); 
											while($row=mysql_fetch_array($selectedplatform))
											{
												$chosen[]=$row['platform_id'];
											}
											//echo 'aaaaaaaaa'.$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1].$tempTable[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1]].'aaaa';
											getInputType('listboxedit',$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1],$tempTable[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1]],$chosen);
											echo '</select>';
																					echo '</select>';
										}
										else
										{	getInputType($_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+2],$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1],$tempTable[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1]],'');}
                                    }}
	                                if ($_GET['tbtype'] == 'product' && $_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+2] == 'text'){  
										echo '<tr><td></td><td></td>';
										echo '<td><input readonly type=text name=remLen size=3 maxlength=3 value="250"> characters left</font></td>';
										echo '</tr>';
                                	}
									
									else if ($_GET['tbtype'] == 'product' && $_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+2] == 'text_paypal'){  
										echo '<tr><td></td><td></td>';
										echo '<td><input readonly type=text name=remLen2 size=3 maxlength=3 value="250"> characters left</font></td>';
										echo '</tr>';
                                	}
																		
                                }
                            
                            
                            ?>
                            
                            
                            <tr>
                                <th></th>
                                <th></th>
                                <td><input type="submit" name="btnsave" value="Save"/></td>
                            </tr>
                        </table>
                        </form>
                        <!--body ends-->
                    </div>

                    <!-- end div#welcome -->

                </div>
                <!-- end div#content -->
                <div id="sidebar">
                    <ul>
                    <?php include 'include/nav.php'; ?>
                        <!-- end navigation -->
                        <?php //include 'include/updates.php'; ?>
                        <!-- end updates -->
                    </ul>
                </div>
                <!-- end div#sidebar -->
                <div style="clear: both; height: 1px"></div>
            </div>
            <?php include 'include/footer.php'; ?>
        </div>
        <!-- end div#wrapper -->
    </body>
</html>


