Location: PHPKode > projects > OSShare > osshare-project-v1.0.1/app/controllers/slaveservers_controller.php
<?php
/*
OsShare v1 , 
Coded By Paimpozhil B. , SaravanaKumar M.S.
*/
class SlaveserversController extends AppController {

	var $name = 'Slaveservers';
	var $helpers = array('Html', 'Form' );
	var $layout = 'admin';
	var $uses = array('Slaveserver');
	
	function index() {
		$this->Slaveserver->recursive = 0;
		$this->set('slaveservers', $this->paginate());
	}

	function view($id = null) {
		if(!$id) {
			$this->Session->setFlash('Invalid Slaveserver.');
			$this->redirect(array('action'=>'index'), null, true);
		}
		$this->set('slaveserver', $this->Slaveserver->read(null, $id));
	}

	function add() {
		if(!empty($this->data)) {
			$this->cleanUpFields();
			$this->Slaveserver->create();
			if($this->Slaveserver->save($this->data)) {
				$this->Session->setFlash('The Slaveserver has been saved');
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash('The Slaveserver could not be saved. Please, try again.');
			}
		}
	}

	function edit($id = null) {
		if(!$id && empty($this->data)) {
			$this->Session->setFlash('Invalid Slaveserver');
			$this->redirect(array('action'=>'index'), null, true);
		}
		if(!empty($this->data)) {
			$this->cleanUpFields();
			if($this->Slaveserver->save($this->data)) {
				$this->Session->setFlash('The Slaveserver saved');
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash('The Slaveserver could not be saved. Please, try again.');
			}
		}
		if(empty($this->data)) {
			$this->data = $this->Slaveserver->read(null, $id);
		}
	}

	function delete($id = null) {
		if(!$id) {
			$this->Session->setFlash('Invalid id for Slaveserver');
			$this->redirect(array('action'=>'index'), null, true);
		}
		if($this->Slaveserver->del($id)) {
			$this->Session->setFlash('Slaveserver #'.$id.' deleted');
			$this->redirect(array('action'=>'index'), null, true);
		}
	}
	
	function test($id = null) {
		if(!$id) {
			$this->Session->setFlash('Invalid id for Slaveserver');
			$this->redirect(array('action'=>'index'), null, true);
		}
		$this->set('slaveserver', $this->Slaveserver->read(null, $id));
		$slave = $this->Slaveserver->findbyid($id);
		$activeslave = $slave["Slaveserver"];
		$ftpstatus = "";
		if($activeslave["ftphost"]=="sameserver" && $activeslave["ftpuser"]=="sameserver" && $activeslave["ftppass"]=="sameserver")
		{
			$ftpstatus .= " Trying to Copy a test file to the slave <br /><br />";
			if(copy((WWW_ROOT . "img" . DS . "testftp.jpg"),$activeslave["ftpdirectory"] . DS . "testftp.jpg"))
			{
				$ftpstatus .= " Copy to Slave Successful <br /><br />";
			}
			else
			{
				$ftpstatus .= " Copy to Slave Failed <br /><br />";
			}
		}
		else
		{
			$conn_id = ftp_connect($activeslave["ftphost"],21,10);
			if($conn_id)
			{
			$login_result = ftp_login($conn_id, $activeslave["ftpuser"], $activeslave["ftppass"]);
			 
			
			if ((!$conn_id) || (!$login_result)) {  // check connection
					$ftpstatus = "Not Connected To FTP <br /><br />";
				 } else {
				 $ftpstatus = " Connected To FTP <br /><br />";
				 //    echo "Connected to $ftp_server, for user $ftp_user_name <br />";
			  }
			  
			  ftp_chdir($conn_id, $activeslave["ftpdirectory"] );
			  $upload = ftp_put($conn_id, "testftp.jpg",(WWW_ROOT . "img" . DS . "testftp.jpg"), FTP_BINARY);  // upload the file					
			  if (!$upload) {  // check upload status
				$ftpstatus .= "Uploading Failed <br /><br />";
			  } else {
				 $ftpstatus .= "Uploaded <br /><br />";
				 
			  }
		
			  ftp_close($conn_id); // close the FTP stream
			}
		}
			$this->set('ftpstatus',$ftpstatus);
		}
	

}
?>
Return current item: OSShare