Wednesday, 29 July 2015

STOP loading previous pages when chrome browser started in ubuntu

While Google gets to work fixing the Chrome battery drain issue affecting Windows users, an easy interim solution may help preserve laptop battery life in the meantime.
The fix? Closing the browser when it’s not needed.

Captain Obvious

Historically, closing an application in Windows is straightforward: you click or tap on the ‘x’ window control button.
Depending on your settings, this isn’t always the case with Chrome; closing doesn’t always mean it fully exits. The browser often continues to run in the background on Windows (and Linux) – something you might never notice.

The Reason Why: You

Whether this happens or not depends on the sort of applications and extensions you have installed in Chrome. Some of these will “ask” the browser to stay awake so that they can continue to function; e.g., to deliver notifications of new e-mail messages or keep an active IRC chat alive.
Google makes it easy to tell when background apps are active: just look for the Google Chrome icon in the system tray (bottom right corner of your desktop screen). Click on this emblem to view a list of active tasks and a access a proper ‘Exit’ option.
If want to stop Chrome from running in the background entirely (i.e., so that it always exits when closed), regardless of extension, you can. You just need to tell it to.

How to Stop Chrome Running in the Background

On Windows or Linux click on the Chrome icon in the task bar/system tray, find the ‘Let Chrome run…’ option and click/tap it to disable/toggle the checkmark off.
It’s that simple. 
The behaviour can also be changed through the browser’s main settings page:
  • Click on the Chrome menu (or press Alt+E)
  • Select Settings
  • Click on the link titled ‘Show advanced settings
  • Under the section headed ‘System‘ untick the box next to “Continue running background apps when Google Chrome is closed”
To reenable the feature simply repeat the steps above but reversing the final step.

Friday, 12 June 2015

CSS to display html table header for each page, also nowrap defining in td

NOTE: Use IE version above 9 to use this, check the print preview before printing. If the content not adjusting set the adjust width property according to page. Set the page set up before.

<style type="text/css">
table,tr,td,th
{
   font-family: arial;vardana;acourier;
   font-size: 8pt;
   border: 1px solid black;
   border-collapse: collapse;
   page-break-inside: auto;
   background: white;
}
th.c1
{
 -moz-transform: rotate(-90deg);
}
thead{
  background: #FFF;
}
@media print
{
  table { page-break-after: always; }
  tr { page-break-inside: avoid; page-break-after: auto; }
  td { page-break-inside: avoid; page-break-after: auto; }
  thead { display: table-header-group; }
}
</style>


and while defining table header declare in php as ...

echo "<table border=1 cellspacing=\"0\" cellpading=\"0\" width=\"100%\">";
echo "<thead>";
echo "<tr>";
echo "<th colspan=20><center><font size=4>SPECIAL RECRUITMENT DRIVE FOR FILLING UP OF BACKLOG VACANCIES FOR THE PERSONS WITH DISABILITIES - Sep-2013,  HYDERABAD DISTRICT</font></center>";
echo "<br/>";
if($cat==='4')
echo "<center><font size=3>Merit List For the post of : Sweeper/Scavanger/Thoti/Ayah , Category-$dis-$tgen, &nbsp;&nbsp; Qualification : Read & Write,  No.of Posts: $nop  </b></font></center>";
else if($cat==='-')
echo "<center><font size=2>For the post of <b>Attendar,Sweeper,Lab attendent,MNO,Dhobi,Thoti,Ayah,Scavenger,Watchman and Helper</b></font></center>";
else
echo "<center><font size=3>Merit List For the post of : <b>$pname ,  Category: $dis-$tgen ,  $qualification &nbsp; No. of posts: $nop</b></font></center>";
echo "</th>";
echo "</tr>";
echo "<tr>";
echo  "<th colspan=14><font size=2>Note: MPD-Multiple Disabled, FMD-Family Member(s) Disabled, C/K/W- Cook/Kamati/Sweepper</font></th>";
echo  "<th colspan=5 align=center><font size=3>WAITAGE MARKS</font></th>";
echo "<th></th>";
echo "</tr>";
echo "<tr>";
echo "<th><font size=2><center>Sl. No.</center></font></th>";
echo "<th><font size=2><center>Reg. No.</center></font></th>";
echo "<th><font size=2><center>Post Applied</center></font></th>";
echo "<th><font size=2><center>Name of the Candidate<br>S/o,D/o,H/o</center></font></th>";
echo "<th><font size=2><center>Sex</center></font></th>";
echo "<th><font size=2><center>DOB</center></font></th>";
echo "<th><font size=2><center>Age (in yrs)<br>As On 01-07-2013</center></font></th>";
echo "<th><font size=2><center>Disable Type<br>%</center></font></th>";
echo "<th><font size=2><center>L/NL</center></font></th>";
echo "<th><font size=2><center>MPD<br>(Yes/No)</center></font></th>";
echo "<th><font size=2><center>FMD<br>(Yes/No)</center></font></th>";
echo "<th><font size=2><center>Caste</center></font></th>";
echo "<th><font size=2><center>Acacdemi Qualifn.<br>Marks</center></font></th>";
echo "<th><font size=2><center>Technical Qualifn.</center></font></th>";
echo "<th><font size=2><center>Age</center></font></th>";
echo "<th><font size=2><center>Disa<br>bility</center></font></th>";
echo "<th><font size=2><center>MPD</center></font></th>";
echo "<th><font size=2><center>FMD</center></font></th>";
echo "<th><font size=2><center>Total</center></font></th>";
echo "<th><font size=2><center>Remarks</center></font></th>";
echo "</tr>";
echo "</thead>";

then after the data rows can be defined as

echo "<tr>";
echo "<td align=center><font size=2><b>$sno</b></font></td>";
echo "<td align=center><font size=2><b>$tslo</b></font></td>";
echo "<td nowrap=yes align=center><font size=2><b>$tpostname</b></font></td>";
echo "<td nowrap=yes><font size=2><b>$tname<br>$tfname</b></font></td>";
echo "<td align=center><font size=2><b>$tsex</b></font></td>";
echo "<td nowrap=yes align=center><font size=2><b>$tdob</b></font></td>";
echo "<td nowrap=yes align=center><font size=2><b>$age</b></font></td>";
echo "<td nowrap=yes align=center><font size=2><b>$tdis_type-$tdis_per%</b></font></td>";
echo "<td align=center><font size=2><b>$tlnl</b></font></td>";
echo "<td align=center><font size=2><b>$tmulti_dis</b></font></td>";
echo "<td align=center><font size=2><b>$tofm_dis</b></font></td>";
echo "<td align=center><font size=2><b>$tcaste</b></font></td>";
echo "<td align=center><font size=2><b>$texam_name1<br>$tmarks_exam1/$tmarks_outof1</b></font></td>";
echo "<td align=center><font size=2><b>$texam_name2<br>$texam2</b></font></td>";
echo "<td align=center><font size=2><b>$ma1</b></font></td>";
echo "<td align=center><font size=2><b>$m2</b></font></td>";
echo "<td align=center><font size=2><b>$m3</b></font></td>";
echo "<td align=center><font size=2><b>$m4</b></font></td>";
echo "<td align=center><font size=2><b>$tm_tot</b></font></td>";
echo "<td align=center><b><font size=2>$trem</font></b></td>";
echo "</tr>";

Tuesday, 26 May 2015

Create a link in UBUNTU to a app or module or extension -- how to install fpdf in ubuntu

1. Please login as "root" or admin privilege as root equivalent in terminal and give the following command
    # sudo apt-get install php-fpdf
2. Internet connection should be there, after successful installation there will be a file in the following location
   # ls -l /usr/share/php/fpdf
3. Please create a symbolic link and direct the link to make available on your webserver ( the default location of apache web server is " /var/www/ " ) using the following command
    # ln -s /usr/share/php/fpdf  /var/www/fpdf
4. Reload your webserver
  #/etc/init.d/apache2 restart
  (or)
   #/etc/init.d/apache2 force-reload
   (or)
   #service apache2 restart
5. Make sure PHP commands on web page associated with the conversion to PDF function like this
   <?php
          require('fpdf/fpdf.php');
    ?>
6. Finish.

For further reference ,
https://kokikode.wordpress.com/2010/03/28/how-to-install-php-fpdf-in-ubuntu/

  

Friday, 1 May 2015

Multiple Multi File Upload Handling in YII

Before proceeding create folder names 'uploads' in the application directory that is the folder protected and uploads should be at same location. And give all permissions to the folder in case of linux machine.

First To Handle Multiple files upload there should be a dynamic table entries for each record.

Say, We are handling a File Tracking System. In this case each entry or File may consists of 'N' number of papers or sometimes images, The File moved to concerned then to next concerned and so on finally it closes.

For each movement a new response file is appended to the existing E-File. In this case we need a multi file upload, That is for each file number there are many E-Files associated and each e-file should be stored.

Now Coming to Implementation, Lets have a parent table name 'FTS' in which fileno is the primary key. The child table name 'uploads' in which id is the primary key and a field 'fileno' is a foreign key referencing the Parent table 'FTS' primary key i.e., `FTS`.`fileno`.

Now, The parent table `FTS` have a feild name image or upload any of it as you like. This is just a check field whether the fileno having a attachment or not? so we can say `image varchar(20)` is a field name in FTS.

coming to implementation,

MODEL:
There is nothing to do with the MODEL here, Just we should have the parent and child models thats it.

VIEW:
lets suppose our view name is `createform.php` and we are using the upload functionality while creating a entry in `FTS`

simply add the below widget to the view (createform.php)

 <?php
echo "<font color='red'><b>Scan and upload the E-Files</b></font> <br/>";
echo " (max 3 files can be uploaded)<br/>";

$this->widget('CMultiFileUpload', array(
                'name' => 'images',   // name to the control
                        'max'=>'3',    // Max number of uploads fixed to 3
                'accept' => 'jpeg|jpg|gif|png|pdf', // useful for verifying files
                'duplicate' => 'Duplicate file!', // useful, i think
                'denied' => 'Invalid file type', // useful, i think
/*'options'=>array(
       'onFileSelect'=>'function(e, v, m){ alert("onFileSelect - "+v) }',
         'afterFileSelect'=>'function(e, v, m){ alert("afterFileSelect - "+v) }',
         'onFileAppend'=>'function(e, v, m){ alert("onFileAppend - "+v) }',
         'afterFileAppend'=>'function(e, v, m){ alert("afterFileAppend - "+v) }',
         'onFileRemove'=>'function(e, v, m){ alert("onFileRemove - "+v) }',
 'afterFileRemove'=>'function(e, v, m){ alert("afterFileRemove - "+v) }',
    ), */ // handle to javascript to the events if necessary
));  echo "jpeg/jpg/gif/png/pdf accepted";
?>

and Don't forget (I always forget) to define the HTML Options to the form  in the view, i.e., at the beginning of our view we declare a html <form> equivalent in php language, add the below bold text
line to the form.

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'fts-form',
        'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'), // ADD THIS
)); ?>

 or this way, before your use of CMultiFileUpload
<?php echo CHtml::form('','post',array('enctype'=>'multipart/form-data')); ?>
That's it!!! View Part is completed. The user can upload the files here I restricted to 3 files, but we have to handle the upload files so, we need to do some coding in controller.

CONTROLLER:

As said earlier, we have taken example while creation of entry in FTS we need to handle the uploaded files in create action of controller.

public function actionCreate()
{
$model=new Fts;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

$baseUrl = Yii::app()->baseUrl;
$cs = Yii::app()->getClientScript();

$cs->registerScriptFile($baseUrl.'/js/utility.js');         // Java Script files registration
$cs->registerScriptFile($baseUrl.'/js/validations.js');


if(isset($_POST['Fts']))
{
$model->attributes=$_POST['Fts'];
if($model->validate()){
                    $model->insertFields();      //calling a model function from controller

///////////////////////////////**** UPLOAD FILES HANDLING BEGINNING *****////////////////////////////

$images = CUploadedFile::getInstancesByName('images');
                                               // The control name given is images
            // proceed if the images have been set
$uname=Yii::app()->user->name;   // Getting login username
$username='';
if(strpos($uname,'.')!==false)
$username=substr($str,0,strrpos($str,'.'));
                      /* gets the part before search character i.e., dot(.)  if username is xxx.fts we need only the name xxx so getting that part */
else
$username=$uname;

                        $tosection='';
if(strpos($model->section,'-')!==false)
$tosection=trim(substr($model->section,0,strrpos($model->section,'-')));
                        // gets the part before search character i.e., Hyphen (-)
else
$tosection=$model->section;

$tosection = preg_replace('/\s+/', '', $tosection);  // removing spaces in the string

$fno= $model->fileno;
            if (isset($images) && count($images) > 0) {   // if upload images exists
            $fileno=1;
               foreach ($images as $image => $pic) {
              /* $dt=date("d-m-y H:i:s");
$strdt = preg_replace('/[^0-9]/','',$dt);     // to generate unique filename
$strdt = uniqid();
$strdt = rand(1, 999999);
$strdt = sha1(md5(time()));
$strdt =                       substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyz"), 0, 6); */

$url=$pic->name;
$onlyname=trim(substr($url,0,strrpos($url,'.')));  // gets only name of file excluding extension
$strdt= preg_replace('/[^0-9a-zA-Z]/','',$onlyname);  // taking only characters and numbers from filename
               $filetype = substr($url, strrpos($url, '.') + 1);  // gets the extension of uploaded file i.e., last part after search character

if(!empty($url)){

                    $app_path = Yii::app()->basePath.'/../uploads/';
                    $filename=$fno.'_'.$fileno.'_'.$username.'_to_'.$tosection.'_'.$strdt.'.'.$filetype;
                    if ($pic->saveAs($app_path.$filename)) {
                        $img_add = new Uploads();    // child table object
    $img_add->fileno = $fno;
                        $img_add->image = $filename;
                $img_add->file_year = $model->file_year;
                    $img_add->section = $model->section;
                   // Dialog::message('INFO', "$img_add->section");
 $img_add->save(); // DONE
                    }
                    $fileno= $fileno + 1;
                    }
                 }
$model->image='YES';     // i.e., the model having uploads
}else{
$model->image='NIL';
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if($model->save())
$this->redirect(array('view','id'=>$model->id));
else
Dialog::message('ERROR', "unable to save ");
}else
Dialog::message('ERROR', "unable to save please enter required(red) color fields");
}

$this->render('create',array(
'model'=>$model,
));
}

The images are saved successfully to the database. The same can be applied to Update action.

check how to display a single upload file in CGRID View : http://hemamca.blogspot.in/2015/02/display-urls-of-image-in-cgridview-of.html

********************* DISPLAYING THE FILES IN VIEW ************************

Now , In view we can display the Uploads as hyper links by the below way:

VIEW.PHP : Our view file,

<div>
<center>
<?php
//if(($model->image!='NIL')and($model->image!=null)){
   $fileno=$model->fileno;
   $imgcnt=Uploads::model()->count("fileno='$fileno'");
   if($imgcnt > 1){
              $app_url=Yii::app()->baseUrl.'/uploads/';
              $imgs=Uploads::model()->findAll("fileno='$fileno'");
              echo "<br/>";
              echo "<table id='withborder' border=1 cellspacing=0 cellpadding=0 bgcolor=\"#45E1D5\">";
              echo "<tr> <td  bgcolor=\"#1D5C57\" colspan=4'><font color=\"white\"><b><center>
              The E-Files details for this Inward Entry </center></b></font></td></tr>";
              echo "<tr>";
              echo "<td bgcolor=\"#1D5C57\"><font color=\"white\"><b><center>S.No</center></b></font></td>";
              echo "<td bgcolor=\"#1D5C57\"><font color=\"white\"><b><center>File No</center></b></font></td>";
              echo "<td bgcolor=\"#1D5C57\"><font color=\"white\"><b><center>File Year</center></b></font></td>";
              echo "<td bgcolor=\"#1D5C57\"><font color=\"white\"><b><center>Filename</center></b></font></td>";
              echo "</tr>";
              $fno=1;
              foreach($imgs as $img){
                       $inwno=$img->fileno;
                       $inwyr=$img->file_year;
                       $fname=$img->image;
                       $filepath=$app_url.$fname;
                       echo "<tr>";
                       echo "<td><font color=\"black\"><center>$fileno</center></font></td>";
                       echo "<td><font color=\"black\"><center>$inwno</center></font></td>";
                       echo "<td><font color=\"black\"><center>$inwyr</center></font></td>";
                       echo "<td><font color=\"black\"><b><a href='$filepath' target='_blank'>$fname </a></b></font></td>";
                echo "</tr>";
                $fno=$fno+1;
              }
              echo "</table>";
echo "<br/>";
}
//}
?>
  </center>
</div>

NOTE: 
Database used is Mysql, Development Language is PHP, framework is PHP.

cross reference site:
http://www.yiiframework.com/wiki/176/uploading-multiple-images-with-cmultifileupload/

UPLOAD a File in yii

THE MODEL

First declare an attribute to store the file name in the model class (either a form model or an active record model). Also declare a file validation rule for this attribute to ensure a file is uploaded with specific extension name.
class Item extends CActiveRecord
{
    public $image;
    // ... other attributes
 
    public function rules()
    {
        return array(
            array('image', 'file', 'types'=>'jpg, gif, png'),
        );
    }
}
You can add others validation parameters as described in CFileValidator. For instance, one can add a “maxSize” restriction (the PHP ini settings will of course prevail).

THE CONTROLLER

Then, in the controller class define an action method to render the form and collect user-submitted data.
class ItemController extends CController
{
    public function actionCreate()
    {
        $model=new Item;
        if(isset($_POST['Item']))
        {
            $model->attributes=$_POST['Item'];
            $model->image=CUploadedFile::getInstance($model,'image');
            if($model->save())
            {
                $model->image->saveAs('path/to/localFile');
                // redirect to success page
            }
        }
        $this->render('create', array('model'=>$model));
    }
}
CUploadedFile::saveAs() in one of the methods of CUploadedFile. You can also access directly to the file through its “tempName” property.

THE VIEW

Finally, create the action view and generate a file upload field.
$form = $this->beginWidget(
    'CActiveForm',
    array(
        'id' => 'upload-form',
        'enableAjaxValidation' => false,
        'htmlOptions' => array('enctype' => 'multipart/form-data'),
    )
);
// ...
echo $form->labelEx($model, 'image');
echo $form->fileField($model, 'image');
echo $form->error($model, 'image');
// ...
echo CHtml::submitButton('Submit');
$this->endWidget();
Another syntax is to use static calls in CHtml instead of CActiveForm. The result is the same as above.
<?php echo CHtml::form('','post',array('enctype'=>'multipart/form-data')); ?>
...
<?php echo CHtml::activeFileField($model, 'image'); ?>
...
<?php echo CHtml::submitButton('Submit'); ?>
<?php echo CHtml::endForm(); ?>