<?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']))
            {
            	$saveState=TRUE;
            	

				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;
					}
				}
            	elseif ($_GET['tbtype']=='customsolution')
				{
					$logo_path = "logo/";
	            	$logo_path = $logo_path . basename( $_FILES['uploadimage']['name']); 
	            	
		            if(!move_uploaded_file($_FILES['uploadimage']['tmp_name'], $logo_path))
		            {
					    $saveMsg = "There was an error uploading the logo, 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)
							{
								$setData = $setData . "'" . $_FILES['uploadimage']['name'] . "',";
							}
							elseif ($i==25)
							{
								$setData = $setData . "'" . $_FILES['uploadfile']['name'] . "',";
							}
                    }
                 elseif(($_GET['tbtype']=='customsolution') && ($i==16 || $i==13))
                    {
                    	if ($i==13)
							{
								$setData = $setData . "'" . $_FILES['uploadimage']['name'] . "',";
							}
						elseif ($i==16)
							{
								$count= count($_POST['platform']);
		                    	$tmp=0;$str='';
		                    	if($_POST['platform']!=''){
			                    	foreach($_POST['platform'] as $list) {
			                    	//$tmp=$tmp+1;
									saveData('tb_supported_customplat', "LAST_INSERT_ID(),'".$list."'", "" ,'new');
			                    	//if($count!=$tmp)
			                    	//{$str = $str.$list;}
			                    	//else{$str = $str.','.$list;}
			                    	}	       
		                    	}             
										$setData = $setData . "'" . $str ."',";
							}
                    }
                    else{
                    	$setData = $setData . "'" . $_POST[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i]] ."',";
                    }
                    
                 }
            	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'] ."'",'new');
                 if ($_GET['tbtype']=='product')
				 {
					$setLangData="";
					$setLangData = $setLangData . "LAST_INSERT_ID(),";
					$setLangData = $setLangData . "'" . $_POST[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][7]] ."'";
					saveData('tb_supported_language',$setLangData,'','new');
					                
					$setPData="";
					$setPData = $setPData . "LAST_INSERT_ID(),";
					$setPData = $setPData . "'" . $_POST[$_SESSION['SESS_ARR'][2][$_GET['tbtype']][10]] ."'";
					//saveData('tb_supported_platform',$setPData,'','new');

					//saveData('tb_supported_platform', "", "product_id=".$_GET['id'] ,'delete');
	                if($_POST['platform']!=''){
		            	foreach($_POST['platform'] as $list) {
						saveData('tb_supported_platform', "LAST_INSERT_ID(),'".$list."'", "" ,'new');
		                    	}	       
	                    	}             
				 	}
       			}
       }
?>

<!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" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="js/datetimepicker.js"></script>

<script type="text/javascript">
/*tinyMCE.init({
        mode : "specific_textareas",
        editor_selector : "mceEditor"
});
*/
$('#created_date').datetimepicker({
	ampm: true
});

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

<!-- Dynamic 'fix' by: Nannette Thacker -->

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>Add New Data </h1>
                        <!--body-->
                        <form name="frmlogin" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?tbtype=<?php echo $_GET['tbtype'];?>">
                        <table width="100%" border=0>
                            <?php if ($saveState)
                                {
                                    echo "<tr><td colspan='2'></td> <th>Data has been created<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>';
                                            $echtype = getInputType($_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+2],$_SESSION['SESS_ARR'][2][$_GET['tbtype']][$i+1],'','');
                                            echo $echtype.'</tr>';
                                        }
                                   }
                                	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>';
                                	}
                                }
                            ?>
                            <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'; ?>
                    </ul>
                </div>
                <!-- end div#sidebar -->
                <div style="clear: both; height: 1px"></div>
            </div>
            <?php include 'include/footer.php'; ?>
        </div>
        
    </body>
</html>


