Tuesday, September 16, 2014

PHP Drupal: Blank pages or "white screen of death" (WSOD)

Change the shutdown handler And it works to show error details!

One way to force errors to display is to change the shutdown handler. Add the following code (originally from http://stackoverflow.com/questions/1475297/phps-white-screen-of-death), to the front of index.php:
<?php
// -------------------------------------------------------
// - Display Errors
// -------------------------------------------------------
ini_set('display_errors', 'On');
ini_set('html_errors', 0);
// -------------------------------------------------------
// - Error Reporting
// -------------------------------------------------------
error_reporting(-1);
// -------------------------------------------------------
// - Shutdown Handler
// -------------------------------------------------------
function ShutdownHandler()
{
    if(@is_array($error = @error_get_last()))
    {
        return(@call_user_func_array('ErrorHandler', $error));
    };
    return(TRUE);
};
register_shutdown_function('ShutdownHandler');
// -------------------------------------------------------
// - Error Handler
// -------------------------------------------------------
function ErrorHandler($type, $message, $file, $line)
{
    $_ERRORS = Array(
        0x0001 => 'E_ERROR',
        0x0002 => 'E_WARNING',
        0x0004 => 'E_PARSE',
        0x0008 => 'E_NOTICE',
        0x0010 => 'E_CORE_ERROR',
        0x0020 => 'E_CORE_WARNING',
        0x0040 => 'E_COMPILE_ERROR',
        0x0080 => 'E_COMPILE_WARNING',
        0x0100 => 'E_USER_ERROR',
        0x0200 => 'E_USER_WARNING',
        0x0400 => 'E_USER_NOTICE',
        0x0800 => 'E_STRICT',
        0x1000 => 'E_RECOVERABLE_ERROR',
        0x2000 => 'E_DEPRECATED',
        0x4000 => 'E_USER_DEPRECATED'
    );
    if(!@is_string($name = @array_search($type, @array_flip($_ERRORS))))
    {
        $name = 'E_UNKNOWN';
    };
    return(print(@sprintf("%s Error in file \xBB%s\xAB at line %d: %s\n", $name, @basename($file), $line, $message)));
};
$old_error_handler = set_error_handler("ErrorHandler");
?>

Drupal 7 on Ubuntu 14.04 [32 bit] : can't install modules with wsod

https://www.drupal.org/node/2281195

I've installed a fresh Drupal 7.28 over a clean Ubuntu 14.04. The environment is virtualbox 4.3 with 4Gb ram an 8Gb disk (hosted by win7). PHP version is 5.5.9-1ubuntu4 and db is mysql. The installed site, empty, works normally.
issue

Trying to install any module via URL leads to WSOD or downloading the module package manually the install button does nothing. After the white page i can go back and continue to navigate the site with no errors or warnings.

Fatal Error
Call to undefined function gzopen()
File: .../drupal-7.31/modules/system/system.tar.inc:716
706:           }
707:
708:           // ----- File to open if the local copy
709:           $v_filename = $this->_temp_tarname;
710:
711:         } else
712:           // ----- File to open if the normal Tar file
713:           $v_filename = $this->_tarname;
714:
715:         if ($this->_compress_type == 'gz')
716:             $this->_file = @gzopen($v_filename, "rb");
717:         else if ($this->_compress_type == 'bz2')
718:             $this->_file = @bzopen($v_filename, "r");
719:         else if ($this->_compress_type == 'none')
720:             $this->_file = @fopen($v_filename, "rb");

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
only tar.gz does not work, zip works fine for me
jabecz commented

I am facing the same problem. I use drupal on other Ubuntu 14.04 servers, but all of them are 64-bit. This server which is going to WSOD on tar.gz module installation is the only one running Ubuntu 14.04 32-bit. So I think the problem is only on 32-bit Ubuntu 14.04 server edition.

I am not able to troubleshoot this problem so I reinstall the server to Ubuntu 14.04 64-bit and see if it helps.

Have You resolved the issue?

Thanks


^^^^^^^^^^^^^^^^^^THIS WORKED FOR ME,THANKS^^^^^^^^^^^^^^^^^^
Zlib missing gzopen is PHP5 bug on 32bit systems
malc_b commented

I have the same issue. This seems to be known bug, that was fixed and has now come back. It only affects 32bit systems. In php5, with big files option, in zlib there is no gzopen only gzopen64. The latest (1.3.12) pear package archive_tar includes a test that checks if gzopen doesn't exist and gzopen64 does, and then it defines its open gzopen to call gzopen64. That fix is close but flawed too, and it doesn't help with Drupal (7, at least) which doesn't call the pear package but has its own (older) copy in core module system.tar.inc.

The fix is to edit system.tar.inc (/var/www/drupal/modules/system/system.tar.inc for my box) to add, after

define ('ARCHIVE_TAR_ATT_SEPARATOR', 90001);
define ('ARCHIVE_TAR_END_BLOCK', pack("a512", ''));

these lines to system.tar.inc
if (!function_exists('gzopen') && function_exists('gzopen64')) {
    function gzopen($filename, $mode, $use_include_path = 0)
    {
        return(gzopen64($filename, $mode, $use_include_path));
    }
}
if (!function_exists('gztell') && function_exists('gztell64')) {
    function gztell($zp)
    {
        return(gztell64($zp));
    }
}
if (!function_exists('gzseek') && function_exists('gzseek64')) {
    function gzseek($zp, $offset, $whence = SEEK_SET)
    {
        return(gzseek64($zp, $offset, $whence));
    }
}

Or I guess to some other module if you wish.

Wednesday, September 10, 2014

HTML5: output tag

From w3school.com:
Attributes
= New in HTML5.
AttributeValueDescription
forelement_idSpecifies the relationship between the result of the calculation, and the elements used in the calculation
formform_idSpecifies one or more forms the output element belongs to
namenameSpecifies a name for the output element

Sample Code ( number HTML5 input type and  range HTML5 input type ):
<form oninput="amount.value = (hours.valueAsNumber * rate.valueAsNumber) + ((hours.valueAsNumber * rate.valueAsNumber) * vat.valueAsNumber)" onsubmit="return false">
<legend>Invoice</legend>
<label for="hours">Number of hours:</label>
 <input id="hours" min="0" name="hours" type="range" value="5" />100
<label for="rate">Rate:</label>
 <input id="rate" min="0" name="rate" type="number" value="1" />($'s)
<label for="vat">VAT:</label>
 <input id="vat" min="0" name="vat" type="number" value="0.20" />
Total: <strong>$<output for="hours rate vat" name="amount"></output>
</form>
Invoice
100
($'s)

Total: $

HTML5: datalist tag - an "autocomplete" feature for input field

From w3school.com:
The <datalist> tag specifies a list of pre-defined options for an <input> element.
The <datalist> tag is used to provide an "autocomplete" feature on <input> elements. Users will see a drop-down list of pre-defined options as they input data.
Use the <input> element's list attribute to bind it together with a <datalist> element
The <datagrid> tag should be avoided in any HTML code because it has been dropped from the HTML specification (or at least deferred)


<input list="browsers" name="browser">
<datalist id="browsers">
  <option value="Internet Explorer">
  <option value="Firefox">
  <option value="Chrome">
  <option value="Opera">
  <option value="Safari">
</datalist>

Sunday, September 7, 2014

JavaScript: RegExp’s exec() function and String’s match() function

Code(credit to georg) :
re_once = /([a-z])([A-Z])/
re_global = /([a-z])([A-Z])/g

st = "aAbBcC"

console.log("match once=", st.match(re_once), "match global=", st.match(re_global))
console.log("exec once=", re_once.exec(st), "exec global=", re_global.exec(st))
console.log("exec once=", re_once.exec(st), "exec global=", re_global.exec(st))
console.log("exec once=", re_once.exec(st), "exec global=", re_global.exec(st))
Result:
match once= ["aA", "a", "A"] match global= ["aA", "bB", "cC"]

exec once= ["aA", "a", "A"] exec global= ["aA", "a", "A"]
exec once= ["aA", "a", "A"] exec global= ["bB", "b", "B"]
exec once= ["aA", "a", "A"] exec global= ["cC", "c", "C"]

Secrets of the JavaScript Ninja :
using a local regular expression (one without the global flag g) with the String object’s match() methods returns an array containing the entire matched string, along with any matched captures in the operation.

But when we supply a global regular expression (one with the g flag included),match() returns something rather different. It’s still an array of results, but in the case of a global regular expression, which matches all possibilities in the candidate string rather than just the first match,  the array returned contains the global matches; captures within each match aren’t returned in this case.

If captures are important to us, we can regain this functionality while still performing a global search by using the regular expression’s exec() method. This method can be repeatedly called against a regular expression, causing it to return the next matched set of information every time it’s called.

Here a simple example of exec() in action that Steven Levithan put...
I needed to created an array containing the indices of each tab character within a string, so I used something like the following:

var tabIndices = [];
var tabMatchInfo;
var tabRegex = /\t/g;

while (tabMatchInfo = tabRegex.exec(string)) {
     tabIndices.push(tabMatchInfo.index);
}

Nice and easy. To do this without exec, it would require something like the following:

var tabIndices = [];
var thisTabIndex;

for (var i = 0; i < string.length; i++) {
     thisTabIndex = string.indexOf(String.fromCharCode(9), i);
     if (thisTabIndex === -1) {
         break;
     } else {
                tabIndices.push(thisTabIndex);
                i = thisTabIndex;
              }
}

Tuesday, August 19, 2014

AngularJS: paging

There should be better way to do the paging for AngularJS. However this is my version of paging, and it works.
<div id='xxxPaging' ng-show="getPageTotal().length > 1">
     <span ng-class="{spanLink:!hover,spanLinkhover:hover}" ng-mouseover="hover=true" ng-mouseleave="hover = false" ng-click="searchCall('paging',current-1);"  ng-show="1!=current && getPageTotal().length>3"><</span>
       <span ng-repeat="i in getPageTotal() track by $index">

         <b ng-show="i==current" class="spanNoLink">{{i}}</b>     

         <span ng-class="{spanLink:!hover,spanLinkhover:hover}" ng-mouseover="hover=true" ng-mouseleave="hover = false" ng-click="searchCall('paging',i);"  ng-show="i!=current && (i-1 == current || i - 2 == current || i + 1  == current || i + 2 == current || i == 1 || i == getPageTotal().length)">{{i}}</span>

         <span class="spanNoLink" ng-show="i != current && i < getPageTotal().length && (i+ 3 == current || i- 3 == current ) && i+3 != 4">..</span>

      </span>
      <span ng-class="{spanLink:!hover__,spanLinkhover:hover__}" ng-mouseover="hover__=true" ng-mouseleave="hover__ = false" ng-click="searchCall('paging',current+1);"  ng-show="getPageTotal().length!=current && getPageTotal().length>3">></span>
</div>

Sunday, August 17, 2014

JSON string as stored proc parameter

Thanks to the article converts a JSON string into a table, I am able to send JSON directly to Stored Proc as input param:



ALTER PROCEDURE [XXXXXX].[xxx_xxx_xxxxxxx]
@SearchCriteria NVARCHAR(max)

AS


---------------------------
-- EF use for Dynamic SQL
---------------------------
IF ( @SearchCriteria IS NULL )
BEGIN
      SELECT
          CAST(NULL AS NVARCHAR(5) ) AS Category,
            CAST(NULL AS NVARCHAR(100)) AS FinancialInstitution,
            CAST(NULL AS NVARCHAR(50)) AS CompanyType,
            CAST(NULL AS NVARCHAR(10)) AS Redeemable,
            CAST(NULL AS NVARCHAR(10)) AS CompoundFreq,
            CAST(NULL AS NVARCHAR(10)) AS PaymentFreq,
            CAST(NULL AS DECIMAL(12,2)) AS MinAmount,
            CAST(NULL AS DECIMAL(12,2) ) AS MaxAmount,
            CAST(NULL AS DECIMAL(5,2)) AS TERM,
            CAST(NULL AS DECIMAL(8,4) ) AS Rate
END

BEGIN



DECLARE @termVal DECIMAL(5,2);
DECLARE @termDY NVARCHAR(300);
DECLARE @termDYSelectedTogether NVARCHAR(400) = '';
--TermTarget
DECLARE @termTarget NVARCHAR(5) = '';

DECLARE @minDeposit NVARCHAR(200);
DECLARE @minDepositSelectedTogether NVARCHAR(260) = '';




DECLARE @interestRate DECIMAL(8,4);
DECLARE @companySelected NVARCHAR(max) ;
DECLARE @companySelectedTogether NVARCHAR(max) = '';

DECLARE @companyTypeSelected NVARCHAR(max) ;
DECLARE @companyTypeSelectedTogether NVARCHAR(max) = '';

DECLARE @redeemSelected NVARCHAR(25) ;
DECLARE @redeemSelectedTogether NVARCHAR(25) = '';

DECLARE @taxIndicatorSelected NVARCHAR(25) ;
DECLARE @taxIndicatorSelectedTogether NVARCHAR(25) = '';

DECLARE @compoundFreqSelected NVARCHAR(50) ;
DECLARE @compoundFreqSelectedTogether NVARCHAR(50) = '';
DECLARE @PaymtFreqSelected NVARCHAR(80) ;
DECLARE @PaymtFreqSelectedTogether NVARCHAR(80) = '';
DECLARE @tbl TABLE
( id int, name NVARCHAR(255), value NVARCHAR(max),  errcnt int,msg varchar(8000)
);

INSERT INTO
      @tbl
SELECT
      id,
      name,
      value,
      errcnt,
      msg
FROM
      dbo.fn_SplitJson2(@SearchCriteria,null);


------------------------------
--Term
------------------------------

SELECT
      @termTarget = value
FROM
      @tbl
WHERE
      name = 'TermTarget'

IF @termTarget <> ''
BEGIN
      SELECT
            @termVal = value
      FROM
            @tbl
      WHERE
            name = 'Months'
END
ELSE
BEGIN
      SELECT
            @termDY = value
      FROM
            @tbl
      WHERE
            name = 'Months'


      --@termDYSelectedTogether
      IF @termDY <> 'ALL'
      BEGIN
      IF @termDY <> ''
        BEGIN
                  SELECT
                  @termDYSelectedTogether=
                     CASE WHEN COALESCE(@termDYSelectedTogether,'')=''
                        THEN  QUOTENAME(value,'''')
                        ELSE  @termDYSelectedTogether+',' + QUOTENAME(value,'''')
                     END
                  FROM
                  dbo.fn_SplitJson2(
                  @termDY,NULL
                  )
        END
        ELSE
         BEGIN
            SELECT @termDYSelectedTogether= ''
         END
      END

END
------------------------------
--Deposit
------------------------------
SELECT
      @minDeposit = value
FROM
      @tbl
WHERE
      name = 'Deposit'


IF @minDeposit <> 'ALL'
BEGIN
IF @minDeposit <> ''
  BEGIN
            SELECT
            @minDepositSelectedTogether=
               CASE WHEN COALESCE(@minDepositSelectedTogether,'')=''
                  THEN  QUOTENAME(value,'''')
                  ELSE  @minDepositSelectedTogether+',' + QUOTENAME(value,'''')
               END
            FROM
            dbo.fn_SplitJson2(
            @minDeposit,NULL
            )
  END
  ELSE
   BEGIN
      SELECT @minDepositSelectedTogether= ''
   END
END



------------------------------
--Rate
------------------------------
SELECT
      @interestRate = value
FROM
      @tbl
WHERE
      name = 'Rate'

.......
.......