Bug fixes

This commit is contained in:
Hillel Coren 2015-02-26 21:24:49 +02:00
parent bf24e8c40f
commit 854f6777ab
6 changed files with 634 additions and 623 deletions

View File

@ -29,11 +29,16 @@ class InvoiceApiController extends Controller
/*
public function store()
{
if (!Utils::isPro()) {
return Redirect::to('/');
}
$data = Input::all();
$invoice = $this->invoiceRepo->save(false, $data, false);
$response = json_encode($invoice, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders();
return Response::make($response, 200, $headers);
}
*/

View File

@ -1,6 +1,6 @@
<?php
class Utils
class utils
{
public static function isRegistered()
{
@ -14,15 +14,11 @@ class Utils
public static function isDatabaseSetup()
{
try
{
if (Schema::hasTable('accounts'))
{
try {
if (Schema::hasTable('accounts')) {
return true;
}
}
catch (Exception $e)
{
} catch (Exception $e) {
return false;
}
}
@ -77,7 +73,7 @@ class Utils
$userType = Utils::getUserType();
}
$response = new stdClass;
$response = new stdClass();
$response->message = isset($_ENV["{$userType}_MESSAGE"]) ? $_ENV["{$userType}_MESSAGE"] : '';
$response->id = isset($_ENV["{$userType}_ID"]) ? $_ENV["{$userType}_ID"] : '';
$response->version = NINJA_VERSION;
@ -89,12 +85,9 @@ class Utils
{
if (Auth::check()
&& !Auth::user()->isPro()
&& $feature == ACCOUNT_ADVANCED_SETTINGS)
{
&& $feature == ACCOUNT_ADVANCED_SETTINGS) {
return '&nbsp;<sup class="pro-label">PRO</sup>';
}
else
{
} else {
return '';
}
}
@ -108,14 +101,10 @@ class Utils
{
$data = [];
foreach ($input as $field)
{
if ($field == "checkbox")
{
foreach ($input as $field) {
if ($field == "checkbox") {
$data[] = $field;
}
else
{
} else {
$data[] = trans("texts.$field");
}
}
@ -125,8 +114,7 @@ class Utils
public static function fatalError($message = false, $exception = false)
{
if (!$message)
{
if (!$message) {
$message = "An error occurred, please try again later.";
}
@ -134,7 +122,7 @@ class Utils
$data = [
'showBreadcrumbs' => false,
'hideHeader' => true
'hideHeader' => true,
];
return View::make('error', $data)->with('error', $message);
@ -149,7 +137,9 @@ class Utils
{
$count = Session::get('error_count', 0);
Session::put('error_count', ++$count);
if ($count > 100) return 'logged';
if ($count > 100) {
return 'logged';
}
$data = [
'context' => $context,
@ -158,7 +148,7 @@ class Utils
'url' => Input::get('url', Request::url()),
'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
'ip' => Request::getClientIp(),
'count' => Session::get('error_count', 0)
'count' => Session::get('error_count', 0),
];
Log::error($error."\n", $data);
@ -174,6 +164,7 @@ class Utils
public static function parseFloat($value)
{
$value = preg_replace('/[^0-9\.\-]/', '', $value);
return floatval($value);
}
@ -192,8 +183,7 @@ class Utils
$lastFour = substr($phoneNumber, -4, 4);
$phoneNumber = '+'.$countryCode.' ('.$areaCode.') '.$nextThree.'-'.$lastFour;
}
else if(strlen($phoneNumber) == 10 && in_array(substr($phoneNumber, 0, 3), array(653, 656, 658, 659))) {
} elseif (strlen($phoneNumber) == 10 && in_array(substr($phoneNumber, 0, 3), array(653, 656, 658, 659))) {
/**
* SG country code are 653, 656, 658, 659
* US area code consist of 650, 651 and 657
@ -205,15 +195,13 @@ class Utils
$lastFour = substr($phoneNumber, 6, 4);
$phoneNumber = '+'.$countryCode.' '.$nextFour.' '.$lastFour;
}
else if(strlen($phoneNumber) == 10) {
} elseif (strlen($phoneNumber) == 10) {
$areaCode = substr($phoneNumber, 0, 3);
$nextThree = substr($phoneNumber, 3, 3);
$lastFour = substr($phoneNumber, 6, 4);
$phoneNumber = '('.$areaCode.') '.$nextThree.'-'.$lastFour;
}
else if(strlen($phoneNumber) == 7) {
} elseif (strlen($phoneNumber) == 7) {
$nextThree = substr($phoneNumber, 0, 3);
$lastFour = substr($phoneNumber, 3, 4);
@ -225,15 +213,13 @@ class Utils
public static function formatMoney($value, $currencyId = false)
{
if (!$currencyId)
{
if (!$currencyId) {
$currencyId = Session::get(SESSION_CURRENCY);
}
$currency = Currency::remember(DEFAULT_QUERY_CACHE)->find($currencyId);
if (!$currency)
{
if (!$currency) {
$currency = Currency::remember(DEFAULT_QUERY_CACHE)->find(1);
}
@ -244,6 +230,7 @@ class Utils
{
$field = $count == 1 ? $string : $string.'s';
$string = trans("texts.$field", ['count' => $count]);
return $string;
}
@ -257,22 +244,28 @@ class Utils
return preg_replace('/([a-z])([A-Z])/s', '$1 $2', $camelStr);
}
public static function timestampToDateTimeString($timestamp) {
public static function timestampToDateTimeString($timestamp)
{
$timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE);
$format = Session::get(SESSION_DATETIME_FORMAT, DEFAULT_DATETIME_FORMAT);
return Utils::timestampToString($timestamp, $timezone, $format);
}
public static function timestampToDateString($timestamp) {
public static function timestampToDateString($timestamp)
{
$timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE);
$format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT);
return Utils::timestampToString($timestamp, $timezone, $format);
}
public static function dateToString($date) {
public static function dateToString($date)
{
$dateTime = new DateTime($date);
$timestamp = $dateTime->getTimestamp();
$format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT);
return Utils::timestampToString($timestamp, false, $format);
}
@ -288,28 +281,27 @@ class Utils
if ($date->year < 1900) {
return '';
}
return $date->format($format);
}
public static function toSqlDate($date, $formatResult = true)
{
if (!$date)
{
return null;
if (!$date) {
return;
}
$timezone = Session::get(SESSION_TIMEZONE);
$format = Session::get(SESSION_DATE_FORMAT);
$dateTime = DateTime::createFromFormat($format, $date, new DateTimeZone($timezone));
return $formatResult ? $dateTime->format('Y-m-d') : $dateTime;
}
public static function fromSqlDate($date, $formatResult = true)
{
if (!$date || $date == '0000-00-00')
{
if (!$date || $date == '0000-00-00') {
return '';
}
@ -317,6 +309,7 @@ class Utils
$format = Session::get(SESSION_DATE_FORMAT);
$dateTime = DateTime::createFromFormat('Y-m-d', $date, new DateTimeZone($timezone));
return $formatResult ? $dateTime->format($format) : $dateTime;
}
@ -326,42 +319,35 @@ class Utils
$format = Session::get(SESSION_DATE_FORMAT);
$date = date_create(null, new DateTimeZone($timezone));
if ($formatResult)
{
if ($formatResult) {
return $date->format($format);
}
else
{
} else {
return $date;
}
}
public static function trackViewed($name, $type, $url = false)
{
if (!$url)
{
if (!$url) {
$url = Request::url();
}
$viewed = Session::get(RECENTLY_VIEWED);
if (!$viewed)
{
if (!$viewed) {
$viewed = [];
}
$object = new stdClass;
$object = new stdClass();
$object->url = $url;
$object->name = ucwords($type).': '.$name;
$data = [];
for ($i=0; $i<count($viewed); $i++)
{
for ($i = 0; $i<count($viewed); $i++) {
$item = $viewed[$i];
if ($object->url == $item->url || $object->name == $item->name)
{
if ($object->url == $item->url || $object->name == $item->name) {
continue;
}
@ -370,8 +356,7 @@ class Utils
array_unshift($data, $object);
if (count($data) > RECENTLY_VIEWED_LIMIT)
{
if (count($data) > RECENTLY_VIEWED_LIMIT) {
array_pop($data);
}
@ -385,8 +370,7 @@ class Utils
}
$variables = ['MONTH', 'QUARTER', 'YEAR'];
for ($i=0; $i<count($variables); $i++)
{
for ($i = 0; $i<count($variables); $i++) {
$variable = $variables[$i];
$regExp = '/:'.$variable.'[+-]?[\d]*/';
preg_match_all($regExp, $str, $matches);
@ -427,15 +411,14 @@ class Utils
private static function getMonth($offset)
{
$months = [ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ];
"July", "August", "September", "October", "November", "December", ];
$month = intval(date('n')) - 1;
$month += $offset;
$month = $month % 12;
if ($month < 0)
{
if ($month < 0) {
$month += 12;
}
@ -451,12 +434,14 @@ class Utils
if ($quarter == 0) {
$quarter = 4;
}
return 'Q'.$quarter;
}
private static function getYear($offset)
{
$year = intval(date('Y'));
return $year + $offset;
}
@ -467,16 +452,11 @@ class Utils
public static function getClientDisplayName($model)
{
if ($model->client_name)
{
if ($model->client_name) {
return $model->client_name;
}
else if ($model->first_name || $model->last_name)
{
} elseif ($model->first_name || $model->last_name) {
return $model->first_name.' '.$model->last_name;
}
else
{
} else {
return $model->email;
}
}
@ -495,8 +475,7 @@ class Utils
$pattern = '/\[([\w]*):([\d]*):(.*)\]/i';
preg_match($pattern, $message, $matches);
if (count($matches) > 0)
{
if (count($matches) > 0) {
$match = $matches[0];
$type = $matches[1];
$publicId = $matches[2];
@ -509,12 +488,14 @@ class Utils
return $message;
}
public static function generateLicense() {
public static function generateLicense()
{
$parts = [];
for ($i = 0; $i<5; $i++) {
$parts[] = strtoupper(str_random(4));
}
return join('-', $parts);
return implode('-', $parts);
}
public static function lookupEventId($eventName)
@ -532,7 +513,8 @@ class Utils
}
}
public static function notifyZapier($subscription, $data) {
public static function notifyZapier($subscription, $data)
{
$curl = curl_init();
$jsonEncodedData = json_encode($data->toJson());
@ -542,7 +524,7 @@ class Utils
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $jsonEncodedData,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Content-Length: ' . strlen($jsonEncodedData)]
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Content-Length: '.strlen($jsonEncodedData)],
];
curl_setopt_array($curl, $opts);
@ -552,13 +534,13 @@ class Utils
curl_close($curl);
if ($status == 410)
{
if ($status == 410) {
$subscription->delete();
}
}
public static function remapPublicIds($data) {
public static function remapPublicIds($data)
{
foreach ($data as $index => $record) {
if (!isset($data[$index]['public_id'])) {
continue;
@ -572,10 +554,12 @@ class Utils
}
}
}
return $data;
}
public static function getApiHeaders($count = 0) {
public static function getApiHeaders($count = 0)
{
return [
'Content-Type' => 'application/json',
//'Access-Control-Allow-Origin' => '*',
@ -603,13 +587,11 @@ class Utils
{
$str = $model->is_deleted || ($model->deleted_at && $model->deleted_at != '0000-00-00') ? 'DISABLED ' : '';
if ($model->is_deleted)
{
if ($model->is_deleted) {
$str .= 'ENTITY_DELETED ';
}
if ($model->deleted_at && $model->deleted_at != '0000-00-00')
{
if ($model->deleted_at && $model->deleted_at != '0000-00-00') {
$str .= 'ENTITY_ARCHIVED ';
}

View File

@ -57,14 +57,12 @@ $monolog->pushHandler(new Monolog\Handler\SyslogHandler('intranet', 'user', Logg
*/
App::error(function(Exception $exception, $code)
{
if (Utils::isNinjaProd())
{
Utils::logError($code . ' ' . Utils::getErrorString($exception));
if (Utils::isNinjaProd()) {
return Response::view('error', ['hideHeader' => true, 'error' => "A {$code} error occurred."], $code);
}
else
{
} else {
return null;
}
});

View File

@ -20,7 +20,7 @@
<h1>{{ trans('texts.confirmation_header') }}</h1>
<p>
{{ $invitationMessage . trans('texts.confirmation_message') }}
{{ $invitationMessage . trans('texts.confirmation_message') }}<br/>
<a href='{{{ URL::to("user/confirm/{$user->confirmation_code}") }}}'>
{{{ URL::to("user/confirm/{$user->confirmation_code}") }}}
</a>

View File

@ -2,6 +2,28 @@
@section('content')
<style type="text/css">
body {
background-color: #f8f8f8;
color: #1b1a1a;
}
.panel-body {
padding-bottom: 100px;
}
</style>
<div class="container">
<p>&nbsp;</p>
<div class="panel panel-default">
<div class="panel-body">
<section data-type="background">
<div class="container">
<div class="row">
@ -148,4 +170,8 @@
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
</div>
</div>
@stop