<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";
include "../includes/arrays.inc.php";
if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}

$message = isset($_GET['msg']) ? $_GET['msg'] : '';

if(isset($_POST['submit']))// && $_POST['submit']=='Update')
{
    (isset($_POST['enable_fbshare'])) ? $enable_fbshare = $_POST['enable_fbshare'] : $enable_fbshare = 'N';
    (isset($_POST['enable_tweet'])) ? $enable_tweet = $_POST['enable_tweet'] : $enable_tweet = 'N';
    (isset($_POST['enable_gplusshare'])) ? $enable_gplusshare = $_POST['enable_gplusshare'] : $enable_gplusshare = 'N';
    (isset($_POST['enable_pinit'])) ? $enable_pinit = $_POST['enable_pinit'] : $enable_pinit = 'N';    
    
    $socialMediaUpdateData = array('enable_fbshare'=>$enable_fbshare,'enable_tweet'=>$enable_tweet,'enable_gplusshare'=>$enable_gplusshare,
                                    'enable_pinit'=>$enable_pinit);
    $tableName             = DbHelper::setTablePrefix('settings');
    DbHelper::update($tableName, $socialMediaUpdateData, 1);
    
    $smIDs = isset($_POST['txtID']) ? $_POST['txtID'] : array();
    if(!empty($smIDs))
    {
        foreach($smIDs as $smID)
        {
            $active = isset($_POST['chkEnable' . $smID]) ? 'Y' : 'N';
            $link = isset($_POST['txtLink' . $smID]) ? trim($_POST['txtLink' . $smID]) : '';
            $updateQuery = "UPDATE ".$tableprefix."social_media
                                SET link='" . mysql_real_escape_string($link) . "',
                                    active='" . $active . "'
                            WHERE social_media_id = '" . $smID . "'";
            mysql_query($updateQuery) or die(mysql_error());
        }
    }
    header('Location:social_media_settings.php?rghtMenu=rghtMenu1&msg='.SM_SETTING_UPDATE_SUCCESS);
}
else if(isset($_POST['submit']) && $_POST['submit']=='Save')
{
    (isset($_POST['enable_fbshare'])) ? $enable_fbshare = $_POST['enable_fbshare'] : $enable_fbshare = 'N';
    (isset($_POST['enable_tweet'])) ? $enable_tweet = $_POST['enable_tweet'] : $enable_tweet = 'N';
    (isset($_POST['enable_gplusshare'])) ? $enable_gplusshare = $_POST['enable_gplusshare'] : $enable_gplusshare = 'N';
    (isset($_POST['enable_pinit'])) ? $enable_pinit = $_POST['enable_pinit'] : $enable_pinit = 'N';    
    
    $socialMediaUpdateData = array('enable_fbshare'=>$enable_fbshare,'enable_tweet'=>$enable_tweet,'enable_gplusshare'=>$enable_gplusshare,
                                    'enable_pinit'=>$enable_pinit);
    $tableName             = DbHelper::setTablePrefix('settings');
    DbHelper::update($tableName, $socialMediaUpdateData, 1);
    
    $smIDs = isset($_POST['txtID']) ? $_POST['txtID'] : array();
    if(!empty($smIDs))
    {
        foreach($smIDs as $smID)
        {
            $active = isset($_POST['chkEnable' . $smID]) ? 'Y' : 'N';
            $link = isset($_POST['txtLink' . $smID]) ? trim($_POST['txtLink' . $smID]) : '';
            $name = ($smID=='1')?'twitter':'facebook';
            $title = ($smID=='1')?'Twitter':'Facebook';
            $logo = ($smID=='1')?'twitter.jpg':'facebook.jpg';
            $insertQuery = "INSERT INTO ".$tableprefix."social_media (
			social_media_id ,
			name,
			title,
			link,
			logo,
			active
			) VALUES (
			'".$smID."',
			'".$name."',
			'".$title."',
			'".mysql_real_escape_string($link)."',
			'".$logo."',
			'".$active."'
			)";

            mysql_query($insertQuery) or die(mysql_error());
        }
    }
    header('Location:social_media_settings.php?rghtMenu=rghtMenu1&msg='.SM_SETTING_SUCCESS);
}

include "../includes/htmltop.php";
    $sql = "SELECT * FROM ".$tableprefix."social_media";
    $result = mysql_query($sql) or die(mysql_error());
    $arrSocial = DbHelper::getResult('settings','enable_fbshare,enable_tweet,enable_gplusshare,enable_pinit',1);
    $socialMediaSettings = $arrSocial[0];    

?>

<body>
<center>
		
		<div align="left" id="layout">
				<!--header area start -->
<?php
	include_once("../includes/topheader_admin.php")
?>
				<!--header area end -->
				<div align="left" class="main_body">
				<!--main body start -->
<?php
		include_once("../includes/admintopmenu.php")
?>
		
		<form action="" method="post" name="frmSMSettings">
		<div align="left" class="content_area">
				<!--content area start -->
				<table cellpadding="0" cellspacing="0" border="0" width="100%">
				
				<tr>
				<td>
				
						<div align="left" class="page_title"><?php echo TXT_EDIT_SOCIAL_MEDIA_SETT;?></div>
						<div align="center" class="text_information_success grey_tr"><?php echo $message?></div>
                                              
						<div align="right">
                                                    <table width="100%" border="0" cellpadding="5" cellspacing="5" class="manage_table">
                                                        <tr>
                                                         <th width="15%" colspan="2">
                                                               <?php echo SOCIAL_MEDIA;?> 
                                                            </th>
                                                            <th  width="25%">
                                                                <?php echo LINK;?>
                                                            </th>
                                                            <th >
                                                                <?php echo ENABLE;?>
                                                            </th>
                                                          </tr>
                                                        <?php
                                                        if(mysql_num_rows($result) != 0)
                                                        {
                                                            while($row =  mysql_fetch_object($result))
                                                            {
                                                        ?>
                                                        <tr>
                                                        <td align="right">
                                                                <img src="../social_media/<?php echo $row->logo; ?>" />
                                                            </td>
                                                            <td valign="center" align="right">
                                                            <?php echo $row->title; ?>
                                                            <input type="hidden" class="textarea2" size="1" name="txtID[]" value="<?php echo $row->social_media_id; ?>" />
                                                        </td>
                                                        <td valign="center" align="right">
                                                            <input type="text" class="textarea2" size="50" name="txtLink<?php echo $row->social_media_id; ?>"  id="txtLink<?php echo $row->social_media_id; ?>" value="<?php echo $row->link; ?>" />
                                                        </td>
														
                                                        <td valign="center" align="center">
                                                            <input type="checkbox" name="chkEnable<?php echo $row->social_media_id; ?>"  id="chkEnable<?php echo $row->social_media_id; ?>" value="1" <?php echo $row->active == 'Y' ? 'checked="checked"' : ''; ?> />
                                                        </td>
                                                    </tr>
                                                    <?php
                                                            }
                                                     ?>
                                                    <tr><td colspan="3"><strong>&nbsp;&nbsp; <?php echo SOCIAL_MEDIA_SHARES;?></strong></td></tr>
                                                    <tr>
                                                        <td></td>    
                                                        <td><img src="../social_media/facebook.png" /></td>
                                                        <td align="left"><?php echo ENABLE_FB;?></td>
                                                        <td valign="center" align="center"><input type="checkbox" name="enable_fbshare"  id="enable_fbshare" value="Y" <?php echo $socialMediaSettings->enable_fbshare == 'Y' ? 'checked="checked"' : ''; ?> /></td>
                                                    </tr>
                                                    <tr>
                                                        <td></td>    
                                                        <td><img src="../social_media/twitter.png" /></td>
                                                        <td align="left"><?php echo ENABLE_TWITTER;?></td>
                                                        <td valign="center" align="center"><input type="checkbox" name="enable_tweet"  id="enable_tweet" value="Y" <?php echo $socialMediaSettings->enable_tweet == 'Y' ? 'checked="checked"' : ''; ?> /></td>
                                                    </tr>
                                                    <tr>
                                                        <td></td>    
                                                        <td><img src="../social_media/gplus.jpg" /></td>
                                                        <td align="left"><?php echo ENABLE_GPLUS;?></td>
                                                        <td valign="center" align="center"><input type="checkbox" name="enable_gplusshare"  id="enable_gplusshare" value="Y" <?php echo $socialMediaSettings->enable_gplusshare == 'Y' ? 'checked="checked"' : ''; ?> /></td>
                                                    </tr>
                                                    <tr>
                                                        <td></td>    
                                                        <td><img src="../social_media/pinterest.png" /></td>
                                                        <td align="left"><?php echo ENABLE_PINTREST;?></td>
                                                        <td valign="center" align="center"><input type="checkbox" name="enable_pinit"  id="enable_pinit" value="Y" <?php echo $socialMediaSettings->enable_pinit == 'Y' ? 'checked="checked"' : ''; ?> /></td>
                                                    </tr>                                                    
                                                     <tr>
                                                        <td colspan="3" align="center">
                                                            <input type="submit" name="submit" value="<?php echo BTN_UPDATE;?>" class="button"/>
                                                        </td>
														<td align="right">&nbsp;
                                                        
                                                        </td>
                                                        </tr>
                                                     <?php
                                                        }else{
                                                    ?>
                                                        <tr>
                                                        <td valign="center" align="right">
                                                            <input type="checkbox" name="chkEnable1"  id="chkEnable1" value="1"  />
                                                        </td>
														<td valign="center" align="right">
                                                            <input type="text" class="textarea2" size="50" name="txtLink1"  id="txtLink1" value="" />
                                                        </td>
														<td valign="center" align="right">
                                                            <?php echo TWITTER;?>
                                                            <input type="hidden" class="textarea2" size="1" name="txtID[]" value="1" />
                                                       
                                                          <img src="../social_media/twitter.jpg" />
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                            
                                                        
                                                        
                                                        <td valign="center" align="right">
                                                            <input type="checkbox" name="chkEnable2"  id="chkEnable2" value="1"  />
                                                        </td>
														<td valign="center" align="right">
                                                            <input type="text" class="textarea2" size="50" name="txtLink2"  id="txtLink2" value="" />
                                                        </td>
														<td valign="center" align="right">
                                                            <?php echo FB;?>
                                                            <input type="hidden" class="textarea2" size="1" name="txtID[]" value="2" />
                                                       
                                                          <img src="../social_media/facebook.jpg" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="3" align="center">
                                                            <input type="submit" name="submit" value="Save" class="button"/>
                                                        </td>
                                                    </tr>
                                                    <?php
                                                        }
                                                    ?>
                                                    
                                                    
                                                    </table>

						</div>
						
						
				<!--content area end-->
				
				<!--content area end-->
				 </td></tr>
			
			</table>	
								
		  </div>
				
				</form>
				
					<div align="right" class="clear_float"><img src="../images/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
?>

<script language="javascript">
function validateFedex()
{
	
	if(document.canadapost.merchatId.value=="")
	{
		alert("Please enter canadapost merchantid");
		document.canadapost.merchatId.focus();
		return false;
	}
	
		
	return true;
	
}	

</script>

