I am working on a codebase developed by an ex-employee, correcting code like:
$x = $y = 0;
while ($x < $interval + 1) {
$looped_date = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + $y, date('Y'));
$formatted_looped_date = implode('/', array_reverse(explode('-', $looped_date)));
$looped_date = implode('', array_reverse(explode('/', $formatted_looped_date)));
$month = "$looped_date[4]$looped_date[5]";
/* bunch of code */
$x++;
$y++;
}
Here are some snippets for the bunch of code above:
if ($range == 'daily') {
if ($type == 'credit') {
$container->cells[] = ' ';
$container->cells[] = $value;
$container->cells[] = '-';
} else {
$container->cells[] = $value;
$container->cells[] = ' ';
$container->cells[] = '-';
}
}
if ($range == 'monthly') {
if ($type == 'credit') {
$container->cells[] = ' ';
$container->cells[] = $value;
$container->cells[] = '-';
} else {
$container->cells[] = $value;
$container->cells[] = ' ';
$container->cells[] = '-';
}
}
// and more 7 if($range)
There’re also functions defined but called just once. Use of Ajax to load a page with an argument, where a function decides 3 other pages to be loaded depending on the argument value. By the way, this value comes straight from the $_GET, with zero validation or treatment. The 3 pages are on a different directory, with no index.*.
One of the Ajax used is activated by an onchange event, and updates a div with an input field, which is raw html returned by one of the 3 files.
There was also this:
function _get_account($id)
{
$sql = "SELECT * FROM table WHERE id = $id";
$res = mysql_query($sql);
if ($id == '0') {
return 'not available';
}
/* loop through $res. I don't know why, since the id column is a primary key, and return the result as an array*/
}
while ($x < $interval + 1) {
// Inside the same loop above, after the many if($range)s
$account = new ourOrmMapper($id);
$container->cells[] = $account->name;
$account_details = _get_account($id);
$container->cells[] = $account_details['amount'];
}
And when I got home, my Windows XP blue-screened before the user login. I can’t reinstall the OS because my HD is SATA, and I don’t have a floppy disk.
I am fucking mad.