Thursday, 28 November 2013

Yii Model beforeSave insert timestamp

    public function beforeSave() {
        if (parent :: beforeSave()) {
            if ($this->isNewRecord) {
                $this->created = new CDbExpression('NOW()');
            } else {
                $this->modified = new CDbExpression('NOW()');
            }
            return true;
        } else {
            return false;
        }
    }

Wednesday, 5 June 2013

Send file via sftp using PHP


  1. Download and enable php_ssh2 extension for php http://downloads.php.net/pierre/
$connection=@ssh2_connect("host", 22);

@ssh2_auth_password($connection,"username","pass");

ssh2_scp_send($connection, 'file', 'file', 0644);

Monday, 27 May 2013

Connect Drupal and Alfresco


  1. Download CMIS API Module http://drupal.org/project/cmis
  2. Download Alfresco http://www.alfresco.com/products/community
  3. Add at ./sites/default/settings.php the following:

    $conf['cmis_repositories'] = array(

    'default' => array(
    'user' => 'user',
    'password' => 'password',
    'url' => 'http://127.0.0.1:8080/alfresco/s/cmis',
    )
    );

  4. Configure module root directory add " \ "


Thursday, 9 May 2013

Node.js Hello world and MySQL Example

var http = require("http");
var mysql = require('mysql'); // required modules

var connection = mysql.createConnection({ // connect to mysql database
  host     : 'localhost',
  port     : '3308',
  database : 'db',
  user     : 'user',
  password : 'password',
});


var data; // store query result
connection.query('SELECT * FROM table', function(err, rows, fields) { // query DB
if (err) throw err;

data = JSON.stringify(rows); // save query as JSON
});


http.createServer(function (request, response) { // create server

  response.writeHead(200, {"Content-Type": "text/html"});
  response.write("<h1>Hello World</h1>");
  response.write("<h2>Jefren Inocando</h2>");
  response.write('<pre>' + data + '</pre>');
  response.end();

}).listen(81);


console.log('Server running at http://127.0.0.1:81');

Friday, 25 January 2013

Yii Autocomplete return multiple values and fill multiple fields

View:

<div class="row">
        <?php echo $form->labelEx($model, 'attribute'); ?>
        <?php
        $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
            'model' => $model,
            'attribute' => 'emp',
            'sourceUrl' => Yii::app()->createUrl('/controller/action'),
            'options' => array(
                'minLength' => '1',
                'select' => 'js:function(event, ui) {
                    $("#field1").val(ui.item.label);
                    $("#field2").val(ui.item.value);
                    return false;
                }'
            ),
            'htmlOptions' => array('size' => 60),
        ));
        ?>
        <?php echo $form->error($model, 'attribute'); ?>
    </div>

Controller:

    public function actionAutocomplete($term) {
        //the $term parameter is what the user typed in on the control
        //send back an array of data:
        $criteria = new CDbCriteria;
        $criteria->compare('field2', $term, true);
        $model = Model::model()->findAll($criteria);

        foreach ($model as $value) {
            $array[] = array('value' => trim($value->field1), 'label' => trim($value->field2));
        }

        echo CJSON::encode($array);
        Yii::app()->end();
    }

PHP - Enable ldap.dll for xampp or Windows server


  1. From C:\xampp\php copy the following files to C:\Windows\system

    • libeay32.dll
    • libsasl.dll
    • ssleay32.dll

  2. Enable php_ldap.dll at php.ini

Thursday, 24 January 2013

Yii connect to MS SQL Server


  1. Dowload Drivers and DLL for PHP http://msdn.microsoft.com/en-us/library/cc296170.aspx
  2. Edit php.ini enable extension
  3. Edit config/main.php db connection string 
              'db' => array(
                   'connectionString' => 'sqlsrv:Server=tcp:123.345.444.333;Database=myDB',
                   'username' => 'username',
                   'password' => 'password',
               ),

Wednesday, 16 January 2013

Yii Ajax loader


<?php
Yii::app()->clientScript->registerScript('loaderScript', '
    $("#loader")
    .hide()
    .ajaxStart(function() {
        $(this).show();
    })
    .ajaxStop(function() {
        $(this).hide();
    });', CClientScript::POS_END);
?>

<?php echo CHtml::image('images/ajax-loader.gif', '', array('id' => 'loader', 'style' => 'margin-left:15px;'));?>

Thursday, 3 January 2013

Yii CGridView with CCheckBoxColumn with ajaxbutton


<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'orders-products-grid',
    'dataProvider' => $model->search(),
    'columns' => array(
        array(
            'header' => 'Item #',
            'value' => '++$row',
        ),
        'products_name',
        'products_quantity',
        array(
            'header' => 'Price',
            'value' => '"$".number_format($data->final_price*$data->products_quantity,2)',
        ),
        array(
            'header' => 'Confirmed?',
            'value' => '$data->bought == 0? "No" : "Yes"',
        ),
        array(
            'class' => 'CCheckBoxColumn',
            'selectableRows' => 2,
            'checked' => '$data->bought==1',
            'id' => 'boughtCheck'
        )
    ),
));
?>

<?php
echo CHtml::ajaxButton('Confirm', yii::app()->createUrl('site/checkBought'), array(
    'type' => 'POST',
    'data' => 'js:{value : $.fn.yiiGridView.getChecked("orders-products-grid","boughtCheck")}',
    'success'=>'js:function(data){
                 $.fn.yiiGridView.update("orders-products-grid");
    }'
));