public function actionDisableinternet($current_url)
 {
     Setup::model()->disableInternetConnection();
     Yii::app()->controller->redirect($current_url);
 }
	
	<tr>
		<td colspan="2">
		<?php 
//$send_order_url=Yii::app()->request->baseUrl.'/PurchaseOrder/SendOrder/'.$purchase_id;
//$send_order_url=Yii::app()->request->baseUrl.'/index.php?r=purchaseOrder/SendOrder&id='.$purchase_id;
$send_order_url = $this->createUrl('purchaseOrder/sendOrder', array('id' => $purchase_id));
?>

		
		<?php 
$setupModel = Setup::model()->findByPk(1);
$internet_connected = AdvanceSettings::model()->findByAttributes(array('parameter' => 'internet_connected'));
$current_url = Yii::app()->request->url;
if ($internet_connected->value == 1) {
    if (Setup::model()->checkInternet()) {
        if ($model->order_status < 3) {
            ?>
			<a href="<?php 
            echo $send_order_url;
            ?>
" onclick="return confirm('Are you sure?')"> 
			<?php 
            echo CHtml::button($model->order_status == 1 ? 'Send Order' : 'Resend Order');
            ?>
		 	</a>
		 	<br>
			<small>Ordered will be send via email. Please make sure your mail settings are configured</small>	
		 	<?php 
        } else {
            ?>
 public function copyfiles()
 {
     $msg = '';
     defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
     $xml = simplexml_load_file("temp/tempaddonfile/install_addon.xml");
     $source_file = getcwd() . DS . "temp" . DS . "tempaddonfile" . DS . $xml->install->source->folder;
     $desti_file = getcwd() . DS . $xml->install->destination->folder;
     $msg .= "<br>Source file " . $source_file;
     $msg .= "<br>Destination file " . $desti_file;
     Setup::model()->recurse_copy($source_file, $desti_file);
     $source_file = getcwd() . DS . "temp" . DS . "tempaddonfile" . DS . $xml->install->source->js;
     $desti_file = getcwd() . DS . $xml->install->destination->js;
     $msg .= "<br>Source file " . $source_file;
     $msg .= "<br>Destination file " . $desti_file;
     Setup::model()->recurse_copy($source_file, $desti_file);
     $source_file = getcwd() . DS . "temp" . DS . "tempaddonfile" . DS . $xml->install->source->images;
     $desti_file = getcwd() . DS . $xml->install->destination->images;
     $msg .= "<br>Source file " . $source_file;
     $msg .= "<br>Destination file " . $desti_file;
     Setup::model()->recurse_copy($source_file, $desti_file);
 }
 public function updateVersion($id)
 {
     defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
     $last_successful_step = '';
     $last_successful_step_message = '';
     $step_info = array();
     $setupModel = Setup::model()->findByPk('1');
     //echo $setupModel->version_update_url;
     $update_url_from_db = $setupModel->version_update_url;
     //$request='http://www.rapportsoftware.co.uk/versions_test/latest_callhandling_version.txt';
     $request = $update_url_from_db . '/latest_stocksystem_version.txt';
     $installed_version = Yii::app()->params['software_version'];
     $available_version = $this->curl_file_get_contents($request);
     $server_update_filename = $installed_version . "_to_" . $available_version . "_update_ims.zip";
     //$server_update_filepath = "http://www.rapportsoftware.co.uk/versions_test/";
     $server_update_filepath = $update_url_from_db;
     $server_update_full_filepath = $server_update_filepath . DS . $server_update_filename;
     $update_directory = 'updates_ims';
     $local_desination_server_update_file = $update_directory . DS . $server_update_filename;
     /*THESE VARIABLEUES USED IN STEP 5 & 6*/
     $unzip_folder = $update_directory . DS . $installed_version . "_to_" . $available_version . "_update_ims";
     $setup_file = getcwd() . DS . $unzip_folder . DS . 'setup.json';
     /*THE SETUP FILES IS LIKE CONTENTS OF NEW FILES TO BE COPIED*/
     switch ($id) {
         /*STEP 1*/
         /*Downlaoding the update file*/
         case 1:
             if (!@copy($server_update_full_filepath, $local_desination_server_update_file)) {
                 $errors = error_get_last();
                 $last_successful_step_message = "File Download ERROR: " . $errors['type'] . "<br>" . $server_update_full_filepath;
                 $last_successful_step_message .= "<br />\n" . $errors['message'];
                 $last_successful_step_message .= "<br /><span style='color:red;'>There was some problem in downloading the file from the server. Please check your internet connection. If Problem still persist, contact support at <a href='mailto:support@rapportsoftware.co.uk'>support@rapportsoftware.co.uk</a><br /></span> ";
                 $last_successful_step = 0;
             } else {
                 $last_successful_step = 1;
                 $last_successful_step_message = "Files succesfully downloaded!";
             }
             $message = $this->createMessage($last_successful_step_message, $last_successful_step);
             array_push($step_info, $last_successful_step);
             array_push($step_info, $message);
             return $step_info;
             break;
             /*STEP 2*/
             /*Creating a backup of database*/
         /*STEP 2*/
         /*Creating a backup of database*/
         case 2:
             $db_current_location = getcwd() . DS . 'protected' . DS . 'data' . DS . 'ims.db';
             $db_backup_location = $update_directory . DS . 'backup' . DS . 'version_' . $installed_version . '_database';
             $db_backup_filename = $db_backup_location . DS . 'ver_' . $installed_version . '.data.db';
             if (!file_exists($db_backup_filename)) {
                 if (!is_dir($db_backup_location)) {
                     if (!mkdir($db_backup_location, 0777, true)) {
                         $last_successful_step = 0;
                         $last_successful_step_message = "Cannot create Directory for Database backup, please check permissions";
                         die('Failed to create folders...');
                         break;
                     }
                 }
                 ///end of if dir present at backup location
                 if (!@copy($db_current_location, $db_backup_filename)) {
                     $errors = error_get_last();
                     $last_successful_step = 0;
                     $last_successful_step_message = "<br>Database backup creation error: " . $errors['type'];
                     $last_successful_step_message .= "<br />\n" . $errors['message'];
                     $last_successful_step_message .= "<br /><span style='color:red;'>There was some problem in creating backup of database. Make sure all users are logged out of the system.  If Problem still persist, contact support at <a href='mailto:support@rapportsoftware.co.uk'>support@rapportsoftware.co.uk</a><br /></span> ";
                 } else {
                     $last_successful_step = 2;
                     $last_successful_step_message = "Database successfully Backuped";
                 }
                 ///end of else
             } else {
                 $last_successful_step = 2;
                 $last_successful_step_message = "Database backup skipped because data is already backed up";
             }
             ////end of else of database backup skipped
             $message = $this->createMessage($last_successful_step_message, $last_successful_step);
             array_push($step_info, $last_successful_step);
             array_push($step_info, $message);
             return $step_info;
             break;
             /*STEP 3*/
             /*Creating Backup of Files*/
         /*STEP 3*/
         /*Creating Backup of Files*/
         case 3:
             /*STEP 3*/
             /*Creating Backup of Files*/
             /*Creating Backup of Files*/
             $source = getcwd() . DS . 'protected';
             $dest = $update_directory . DS . 'backup' . DS . 'version_' . $installed_version . '_files' . DS . 'protected';
             if (!is_dir($dest)) {
                 if (!is_dir($dest)) {
                     if (!mkdir($dest, 0777, true)) {
                         $last_successful_step = 0;
                         $last_successful_step_message = "Cannot create Directory for Files backup, please check permissions";
                         die('Failed to create folders...');
                         break;
                     }
                 }
                 if ($this->recurse_copy($source, $dest) == true) {
                     $last_successful_step = 3;
                     $last_successful_step_message = "Files have been successfully backed up";
                 } else {
                     $last_successful_step = 0;
                     $last_successful_step_message = " There was some problem in creating mannual backup of files. Try again to run the backup. If Problem still persist, contact support at <a href='mailto:support@rapportsoftware.co.uk'>support@rapportsoftware.co.uk</a><br /> ";
                 }
             } else {
                 $last_successful_step = 3;
                 $last_successful_step_message = "Files Backup Skipped as there is already a folder";
             }
             $message = $this->createMessage($last_successful_step_message, $last_successful_step);
             array_push($step_info, $last_successful_step);
             array_push($step_info, $message);
             return $step_info;
             break;
             /*STEP 4*/
             /*Unzipping Downloaded files*/
         /*STEP 4*/
         /*Unzipping Downloaded files*/
         case 4:
             $zip = new ZipArchive();
             $res = $zip->open($local_desination_server_update_file);
             if ($res === TRUE) {
                 $zip->extractTo($update_directory);
                 $zip->close();
                 $last_successful_step = 4;
                 $last_successful_step_message = "Downloaded Files have been successfully unzipped";
             } else {
                 $last_successful_step = 0;
                 $last_successful_step_message = " There was some problem in unzippping the downloaded files. If Problem still persist, contact support at <a href='mailto:support@rapportsoftware.co.uk'>support@rapportsoftware.co.uk</a><br /> ";
             }
             $message = $this->createMessage($last_successful_step_message, $last_successful_step);
             array_push($step_info, $last_successful_step);
             array_push($step_info, $message);
             return $step_info;
             break;
             /*STEP 5*/
             /*Modifying the Database*/
         /*STEP 5*/
         /*Modifying the Database*/
         case 5:
             //$json=$this->curl_file_get_contents($setup_file);
             $json = file_get_contents($setup_file);
             $jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($json, TRUE)), RecursiveIteratorIterator::SELF_FIRST);
             /*We will get the location of database update file by following  procedure*/
             $db_update_file = '';
             foreach ($jsonIterator as $key => $val) {
                 /////*Since within the database Key is the location of update file
                 if ($key == 'database') {
                     $db_update_file = getcwd() . DS . $unzip_folder . $val;
                 }
             }
             ///end of foreach iterator
             ////////*NOW By reading the update file we will be changing the main database
             try {
                 $db = new PDO('sqlite:protected' . DS . 'data' . DS . 'ims.db');
                 //	echo '<hr>'.$db_update_file;
                 $file_handle = fopen($db_update_file, 'r');
                 echo "<br />";
                 while (!feof($file_handle)) {
                     $line = fgets($file_handle);
                     if (!empty($line)) {
                         $db->exec($line);
                     }
                 }
                 fclose($file_handle);
                 // close the database connection
                 $db = NULL;
                 $last_successful_step = 5;
                 $last_successful_step_message .= "Database is successfully changed";
             } catch (PDOException $e) {
                 $last_successful_step = 0;
                 $last_successful_step_message = "Unable to Change the Database";
                 print 'Exception : ' . $e->getMessage();
             }
             $message = $this->createMessage($last_successful_step_message, $last_successful_step);
             array_push($step_info, $last_successful_step);
             array_push($step_info, $message);
             return $step_info;
             break;
             /*STEP 6*/
             /*Moving the new files*/
             /*	Development Value 10
              * 	RELEASE VALUE 6
              * */
         /*STEP 6*/
         /*Moving the new files*/
         /*	Development Value 10
          * 	RELEASE VALUE 6
          * */
         case 6:
             $folder = '';
             $non_copied_files = '';
             $non_copied_files_flag = 1;
             $json = file_get_contents($setup_file);
             $jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($json, TRUE)), RecursiveIteratorIterator::SELF_FIRST);
             foreach ($jsonIterator as $key => $val) {
                 if (is_array($val)) {
                     echo "{$key}:<br>";
                     if ($key == 'folders') {
                         $folder = true;
                     } else {
                         $folder = false;
                     }
                     /////end of if of folder check
                 } else {
                     if ($folder) {
                         echo "<hr><span style='color:green;'> {$key} => {$val}</span><br>";
                         ////*COPY FOLDERS NOW
                         $folder_name = $key;
                         $src_folder_name = $key;
                         $folder_copy_from = getcwd() . DS . $unzip_folder . '' . $val;
                         //$folder_copy_to=getcwd().'/protected/'.$folder_name;
                         $folder_copy_to = $this->getDestinationPath($json, $src_folder_name);
                         echo " <span style='color:green;'>";
                         echo "COPY FROM :" . $folder_copy_from;
                         echo "<br>COPY TO :" . $folder_copy_to;
                         echo "</span><hr>";
                         if ($this->recurse_copy($folder_copy_from, $folder_copy_to) == false) {
                             $non_copied_files = "<br>Folder " . $folder_copy_from . "was not coped to" . $folder_copy_to;
                             $non_copied_files_flag = 0;
                             throw new Exception('Unable to copy folders.');
                         } else {
                             $last_successful_step_message = " All new files copied";
                             $last_successful_step = 6;
                         }
                     }
                     ////end of if of copy folders
                 }
                 ///end of else of is_array
             }
             ///end of foreach iterator
             $last_successful_step_message = " All new files copied";
             $last_successful_step = 6;
             $message = $this->createMessage($last_successful_step_message, $last_successful_step);
             array_push($step_info, $last_successful_step);
             array_push($step_info, $message);
             return $step_info;
             break;
         case 7:
             $last_successful_step = 7;
             $last_successful_step_message = "Congrates !! Update Successfully Done ";
             $message = $this->createMessage($last_successful_step_message, $last_successful_step);
             array_push($step_info, $last_successful_step);
             array_push($step_info, $message);
             return $step_info;
             break;
             /*STEP 0*/
             /*Whem Something Fails*/
         /*STEP 0*/
         /*Whem Something Fails*/
         default:
             $last_successful_step_message = "<br /><span style='color:red;'>There is some unknown problem in update progress, Try again !! <br>\r\n\t\t\t\t\t\t If Problem still persist send this screen shot or contact support at <a href='mailto:support@rapportsoftware.co.uk'>support@rapportsoftware.co.uk</a><br /></span> ";
             $last_successful_step = 0;
             $message = "<hr><br><span style='color:red;'>" . $fail_htmltag . " &nbsp;&nbsp;Step-" . $last_successful_step;
             $message .= ": " . $last_successful_step_message . '</span>';
             array_push($step_info, $last_successful_step);
             array_push($step_info, $message);
             return $step_info;
             break;
             //end of default.
     }
     //end of switch($id) opened at the very beginning.
 }
	<link rel="stylesheet" type="text/css" href="<?php 
echo Yii::app()->request->baseUrl;
?>
/css/main.css" />
	<link rel="stylesheet" type="text/css" href="<?php 
echo Yii::app()->request->baseUrl;
?>
/css/form.css" />

	<title><?php 
echo CHtml::encode($this->pageTitle);
?>
</title>
	<?php 
$setupModel = Setup::model()->findByPk(1);
?>
</head>

<body>
<?php 
$company_logo = Yii::app()->request->baseUrl . "/images/company_logo.png";
$rapport_stock_logo = Yii::app()->request->baseUrl . "/images/rapport_stock_logo.png";
?>

<div class="container" id="page">
	
	<table><tr>
		<td style="margin:20px; vertical-align:middle;" ><div id="logo" ><a href="<?php 
echo Yii::app()->request->baseUrl;
?>
 public function actionNotifySupplier($id)
 {
     $model = $this->loadModel($id);
     $setupModel = Setup::model()->findByPk(1);
     $model = $this->loadModel($id);
     $itemsOnOrderModel = $model->getItemsOnOrder($id);
     $reciever_email = $model->suppliers->email;
     $reciever_name = $model->suppliers->contact_person;
     //$sender_email=Yii::app()->params['adminEmail'];
     $sender_email = $setupModel->email;
     //$sender_name=Yii::app()->params['company_name'];
     $sender_name = $setupModel->company;
     $message = new YiiMailMessage();
     $message->setTo(array($reciever_email => $reciever_name));
     $message->setFrom(array($sender_email => $sender_name));
     $message->setSubject('Items missing or damaged - Purchase Order: ' . $model->order_number . ' ');
     $message->setBody($this->renderPartial('finaliseOrder', array('model' => $model), true), 'text/html');
     $numsent = Yii::app()->mail->send($message);
     $numsent = 1;
     if ($numsent == 1) {
         $this->redirect(array('finaliseOrder', 'id' => $model->id));
     } else {
         $this->raiseEvent('Error', 'error');
     }
     //end of else
 }