<?php
/**
 * To manage seotitle contents
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		###StoreSeoTitle###
 * @author 		saravanan_24at09
 * @copyright	Copyright (c) 2008 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: $
 * @since 		2007-09-28
 */
require_once('./common/configs/config.inc.php'); //configurations

//compulsory
$CFG['mods']['is_include_only']['non_html_header_files'] = true;
$CFG['mods']['is_include_only']['html_header'] = false;
$CFG['auth']['is_authenticate'] = false;
$CFG['html']['is_use_header'] = false;

require($CFG['site']['project_path'].'common/application_top.inc.php');

//-------------- Class StoreSeoTitle begins --------------->>>>>//
class DefaultTwitterUser extends FormHandler
	{
		public function checkIfDefaultTwitterUserExists()
			{
				$username = $this->CFG['user']['not_allowed'];
				$sql = 'SELECT name from  '.$this->CFG['db']['tbl']['users'].''.
				       ' WHERE name =\''.$username.'\''; 
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
				    trigger_error($this->dbObj->ErrorNo().' '.$this->dbObj->ErrorMsg(), E_USER_ERROR);
				$numrows = 	$rs->PO_RecordCount();
				if($numrows > 0 )
					return true;
				else
				    return false;
							     
					   
			}
		public function addDefaultTwitterUser()
			{
				 $username = $this->CFG['user']['not_allowed'];
				 $display_name = $this->CFG['user_disp']['not_allowed'];
				 $avatarImageUrl = $this->CFG['site']['url'].$this->CFG['admin']['avatar_path'];
				 $image = 'default_avatar37.jpg';
				 $sql = 'INSERT INTO '.$this->CFG['db']['tbl']['users'].''.
				          ' SET name = \''.$username.'\','.
						  ' display_name = \''.$display_name.'\','.
						  ' sex = \'Male\','.
						  ' img_path = \''.$avatarImageUrl.$image.'\','.
						  ' user_access = \'User\','.
						  ' usr_status = \'Ok\','.
						  ' openid_used = \'Yes\','.
						  ' openid_type = \'twitter\','.
						  ' doj = now()';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
				    trigger_error($this->dbObj->ErrorNo().' '.$this->dbObj->ErrorMsg(), E_USER_ERROR);
				$user_id = $this->dbObj->Insert_ID();			  
				$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['advanced_search'].''.
				        ' SET advanced_search_id = '.$user_id.','.
				        ' user_id = '.$user_id.'';
			   $stmt = $this->dbObj->Prepare($sql);
			   $rs = $this->dbObj->Execute($stmt);
			   if (!$rs)
				   trigger_error($this->dbObj->ErrorNo().' '.$this->dbObj->ErrorMsg(), E_USER_ERROR);		
			   	
			   $sql = 'INSERT INTO '.$this->CFG['db']['tbl']['users_ans_log'].''.
				        ' SET log_id = '.$user_id.','.
				        ' user_id = '.$user_id.','.
						' keyword_mail = \'No\','.
						' reply_mail = \'No\','.
						' favorite_mail = \'No\','.
						' best_ans_mail = \'No\','.
						' abuse_mail = \'No\','.
						' internal_mail = \'No\','.
						' news_letter = \'No\','.
						' widget_order= \'13,14,15,10,11,12,7,8,9,4,5,6,1,2,3\'';
			   $stmt = $this->dbObj->Prepare($sql);
			   $rs = $this->dbObj->Execute($stmt);
			   if (!$rs)
				   trigger_error($this->dbObj->ErrorNo().' '.$this->dbObj->ErrorMsg(), E_USER_ERROR);				   
			   echo $this->CFG['user']['not_allowed']. '&nbsp; &nbsp; user  created  successfully!!<br />';	   
				   
			}
	}
$twitteruser = new DefaultTwitterUser();
$twitteruser->setDBObject($db);
$twitteruser->makeGlobalize($CFG, $LANG);	
if(!$twitteruser->checkIfDefaultTwitterUserExists())	
	{
		$twitteruser->addDefaultTwitterUser();
	}
else
	{
		echo $CFG['user']['not_allowed']. '&nbsp; &nbsp; user already created !!<br />';
	}	