Location: PHPKode > projects > eBlog > admin/sync.php
<?php

/**************************************************************************
 *                                                                        *
 *                                                                        *
 *         Solution: eBlog                                                *
 *          Release: 1.7                                                  *
 *             File: admin/sync.php                                       *
 *               By: Emuci inc.                                           *
 *          Website: http://www.emuci.com                                 *
 *        Copyright: (C) 2010 Emcui inc.                                  *
 *                                                                        *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *                                                                        *
 *   This script is NOT freeware and is subjected to Emuci terms of use   *
 *   located in the docs folder.                                          *
 *                                                                        *
 *                                                                        *
 *************************************************************************/


include 'global.php';

$action = $_GET['action'];

if(empty($action))
{
	$action = "form";
}	

// Only authorised user allowed
if($_SESSION['permission'] == 1){
	
	$conn = mysql_connect($dbhost, $dbuser, $dbpass);
	mysql_select_db($dbname);
		

	if($action == "process")
	{
		$toWrite = "";
		$counter = 0;
		$toWrite =  "<?xml version=\"1.0\" encoding=\"$blog_windows_encoding\"?>\n<eblog>";
		
		
		$query2  = "SELECT * FROM eblog_topics ORDER BY id ASC";
		$result2 = mysql_query($query2);	
		while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC))
		{
			$row2id = $row2['id'];
			$row2title = $row2['title'];
			$row2time = $row2['date'];
			$row2contnet = $row2['contents'];
			$row2sec = $row2['sec'];
			
			
			$result = mysql_query("SELECT status FROM eblog_sec2sync WHERE secID = '$row2sec'");	
			$row = mysql_fetch_row($result);
			$syncStatus = $row[0];
				
			if($syncStatus == 1){
						
			$toWrite = $toWrite . "
									
<topic>
<id>$row2id</id>
<title>$row2title</title>
<timestamp>$row2time</timestamp>
<content>$row2contnet</content>
</topic> \n
		
		";
				$counter++;
			}
			
		}
			
		
		$toWrite = $toWrite . "</eblog>";	
		if($counter < 1)
		{
			$toWrite = "";
		}
			
		
		$filename = "../eblog.xml";
		$fh = fopen($filename, 'w');
		fwrite($fh, $toWrite);
		fclose($fh);
		
		$sn = $_POST['sn'];
		$name = $_POST['name'];
		$username = $_POST['username'];
		$password = $_POST['password'];
		$icon = basename($_FILES['icon']['name']);
		
		if(!empty($icon)){		
			$thumbNewName = '../uploads/'.'profile'.'/'.$icon;
			if (file_exists($thumbNewName))
			{
				$timeNow = date("dmyHis");
				$thumbNewName = '../uploads/'.'profile'.'/'. $timeNow . '_' . $icon;	
			}
			else
			{
				$thumbNewName = '../uploads/'.'profile'.'/'.$icon;
			}
			
			move_uploaded_file($_FILES['icon']['tmp_name'],$thumbNewName);	
			
		
			$query = "UPDATE eblog_sync SET `icon` = '$thumbNewName' WHERE `id` = '1'";
			mysql_query($query);						
		}		
		
		
		$query = "UPDATE eblog_sync SET `sn` = '$sn' WHERE `id` = '1'";
		mysql_query($query);
		
		$query = "UPDATE eblog_sync SET `name` = '$name' WHERE `id` = '1'";
		mysql_query($query);
		
		$query = "UPDATE eblog_sync SET `username` = '$username' WHERE `id` = '1'";
		mysql_query($query);
		
		$query = "UPDATE eblog_sync SET `password` = '$password' WHERE `id` = '1'";
		mysql_query($query);		
		
		  $pageURL = 'http';
		  if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
		  $pageURL .= "://";
		  if ($_SERVER["SERVER_PORT"] != "80") {
		  	$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
		  } else {
		  	$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
		  }
		  $chunk = explode("admin/index.php",$pageURL);
		  $scriptURL = $chunk[0];		
		  $XMLURL = $scriptURL . 'eblog.xml';
		  
		  $iconFIXEDURL = $scriptURL . 'uploads/profile/' . $thumbNewName; 
		
		// send info to eblogics
		echo "<meta http-equiv=\"refresh\" content=\"0;url=http://www.eblogica.com/sync.php?product=eblog&name=$name&username=$username&password=$password&sn=$sn&url=$XMLURL&icon=$iconFIXEDURL\">";					
		
	}
	else
	{		
		
		$result = mysql_query("SELECT * FROM eblog_sync WHERE id = '1'");	
		$row = mysql_fetch_row($result);
		$sn = $row[1];
		$name = $row[2];
		$icon = $row[3];
		$username = $row[4];
		$password = $row[5];		
	
		echo "
		<html dir=\"$blog_dir\">
		<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$blog_windows_encoding\">
		<link href=\"../templates/default/css/style_admin.css\" rel=\"stylesheet\">	
		<script language=\"javascript\">
		  function checkForm(form){
		  
		  if(form.username.value == \"\"){
		  alert( \"$lang_erorr_sync_username\" );
		  form.username.focus();
		  return false;
		  }
		  
		  
		  if(form.password.value == \"\"){
		  alert( \"$lang_erorr_sync_password\" );
		  form.password.focus();
		  return false;
		  }
		  
		  
		  if(form.name.value == \"\"){
		  alert( \"$lang_erorr_sync_name\" );
		  form.name.focus();
		  return false;
		  }
		  
		  
		  if(form.sn.value == \"\"){
		  alert( \"$lang_erorr_sync_sn\" );
		  form.sn.focus();
		  return false;
		  }

	
		  
		  return true;
		  }
			</script>
		
		<br><font face=\"tahoma\" size=\"2\">$lang_admin_notRegistered<br>&nbsp;
		<form method=\"post\" enctype=\"multipart/form-data\" action=\"sync.php?action=process\" onsubmit=\"return checkForm(this);\">
		<table bordercolor=\"#727272\" style=\"border-collapse: collapse\" width=\"100%\" cellSpacing=\"0\" cellPadding=\"5\"  border=\"1\">
		
		<tr bgcolor=\"#f2f2f2\">
		<td width=\"200\">
		<font face=\"tahoma\" size=\"2\">$lang_admin_emuciUsername:<font class=\"light\">*</font></font>
		</td>
		<td>
		<input type=\"text\" value=\"$username\" name=\"username\" style=\"font-family: Tahoma; font-size: 12px;  width:50%; color: #000000; border: 1px solid #000000;\" MAXLENGTH=\"70\">
		</td>
		</tr>
		
		
		<tr bgcolor=\"#dadada\">
		<td width=\"200\">
		<font face=\"tahoma\" size=\"2\">$lang_admin_emuciPassword:<font class=\"light\">*</font></font>
		</td>
		<td>
		<input type=\"password\" value=\"$password\" name=\"password\" style=\"font-family: Tahoma; font-size: 12px;  width:50%; color: #000000; border: 1px solid #000000;\" MAXLENGTH=\"70\">
		</td>
		</tr>
		
		<tr bgcolor=\"#f2f2f2\">
		<td width=\"200\">
		<font face=\"tahoma\" size=\"2\">$lang_admin_nickname:<font class=\"light\">*</font></font>
		</td>
		<td>
		<input type=\"text\" name=\"name\" value=\"$name\" style=\"font-family: Tahoma; font-size: 12px;  width:100%; color: #000000; border: 1px solid #000000;\" MAXLENGTH=\"70\">
		</td>
		</tr>						
		
		<tr bgcolor=\"#dadada\">
		<td width=\"200\">
		<font face=\"tahoma\" size=\"2\">$lang_admin_serialNumber:<font class=\"light\">*</font></font>
		</td>
		<td>
		<input type=\"text\" name=\"sn\" value=\"$sn\" style=\"font-family: Tahoma; width:100%; font-size: 12px; color: #000000; border: 1px solid #000000;\" MAXLENGTH=\"70\">
		</td>
		</tr>
		
		
		<tr bgcolor=\"#f2f2f2\">
		<td width=\"200\">
		<font face=\"tahoma\" size=\"2\">$lang_admin_icon:</font>
		</td>
		<td>
		<input type=\"file\" name=\"icon\" style=\"width:100%;\">
		</td>
		</tr>
					
		
		</table>
		<br>
		<center><input type=\"submit\" value=\"$lang_admin_sync\"></center>
		</form>
		</html>
		";			

	}
	mysql_close($conn);
}
	

			
?>
Return current item: eBlog