mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Bug fixes
This commit is contained in:
parent
bf24e8c40f
commit
854f6777ab
@ -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);
|
||||
}
|
||||
*/
|
||||
|
@ -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 ' <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,16 +114,15 @@ class Utils
|
||||
|
||||
public static function fatalError($message = false, $exception = false)
|
||||
{
|
||||
if (!$message)
|
||||
{
|
||||
if (!$message) {
|
||||
$message = "An error occurred, please try again later.";
|
||||
}
|
||||
|
||||
static::logError($message . ' ' . $exception);
|
||||
static::logError($message.' '.$exception);
|
||||
|
||||
$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,26 +164,26 @@ class Utils
|
||||
public static function parseFloat($value)
|
||||
{
|
||||
$value = preg_replace('/[^0-9\.\-]/', '', $value);
|
||||
|
||||
return floatval($value);
|
||||
}
|
||||
|
||||
public static function formatPhoneNumber($phoneNumber)
|
||||
{
|
||||
$phoneNumber = preg_replace('/[^0-9a-zA-Z]/','',$phoneNumber);
|
||||
$phoneNumber = preg_replace('/[^0-9a-zA-Z]/', '', $phoneNumber);
|
||||
|
||||
if (!$phoneNumber) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if(strlen($phoneNumber) > 10) {
|
||||
if (strlen($phoneNumber) > 10) {
|
||||
$countryCode = substr($phoneNumber, 0, strlen($phoneNumber)-10);
|
||||
$areaCode = substr($phoneNumber, -10, 3);
|
||||
$nextThree = substr($phoneNumber, -7, 3);
|
||||
$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,25 +213,24 @@ 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);
|
||||
}
|
||||
|
||||
return $currency->symbol . number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator);
|
||||
return $currency->symbol.number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator);
|
||||
}
|
||||
|
||||
public static function pluralize($string, $count)
|
||||
{
|
||||
$field = $count == 1 ? $string : $string . 's';
|
||||
$field = $count == 1 ? $string : $string.'s';
|
||||
$string = trans("texts.$field", ['count' => $count]);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
@ -254,25 +241,31 @@ class Utils
|
||||
|
||||
public static function toSpaceCase($camelStr)
|
||||
{
|
||||
return preg_replace('/([a-z])([A-Z])/s','$1 $2', $camelStr);
|
||||
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;
|
||||
$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,10 +370,9 @@ 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]*/';
|
||||
$regExp = '/:'.$variable.'[+-]?[\d]*/';
|
||||
preg_match_all($regExp, $str, $matches);
|
||||
$matches = $matches[0];
|
||||
if (count($matches) == 0) {
|
||||
@ -400,7 +384,7 @@ class Utils
|
||||
$minArray = explode('-', $match);
|
||||
if (count($addArray) > 1) {
|
||||
$offset = intval($addArray[1]);
|
||||
} else if (count($minArray) > 1) {
|
||||
} elseif (count($minArray) > 1) {
|
||||
$offset = intval($minArray[1]) * -1;
|
||||
}
|
||||
|
||||
@ -417,9 +401,9 @@ class Utils
|
||||
$offset = intval($offset);
|
||||
if ($part == 'MONTH') {
|
||||
return Utils::getMonth($offset);
|
||||
} else if ($part == 'QUARTER') {
|
||||
} elseif ($part == 'QUARTER') {
|
||||
return Utils::getQuarter($offset);
|
||||
} else if ($part == 'YEAR') {
|
||||
} elseif ($part == 'YEAR') {
|
||||
return Utils::getYear($offset);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
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)
|
||||
{
|
||||
return $model->first_name . ' ' . $model->last_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
} elseif ($model->first_name || $model->last_name) {
|
||||
return $model->first_name.' '.$model->last_name;
|
||||
} else {
|
||||
return $model->email;
|
||||
}
|
||||
}
|
||||
@ -484,8 +464,8 @@ class Utils
|
||||
public static function encodeActivity($person = null, $action, $entity = null, $otherPerson = null)
|
||||
{
|
||||
$person = $person ? $person->getDisplayName() : '<i>System</i>';
|
||||
$entity = $entity ? '[' . $entity->getActivityKey() . ']' : '';
|
||||
$otherPerson = $otherPerson ? 'to ' . $otherPerson->getDisplayName() : '';
|
||||
$entity = $entity ? '['.$entity->getActivityKey().']' : '';
|
||||
$otherPerson = $otherPerson ? 'to '.$otherPerson->getDisplayName() : '';
|
||||
|
||||
return trim("$person $action $entity $otherPerson");
|
||||
}
|
||||
@ -495,44 +475,46 @@ 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];
|
||||
$name = $matches[3];
|
||||
|
||||
$link = link_to($type . 's/' . $publicId, $name);
|
||||
$link = link_to($type.'s/'.$publicId, $name);
|
||||
$message = str_replace($match, "$type $link", $message);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public static function generateLicense() {
|
||||
public static function generateLicense()
|
||||
{
|
||||
$parts = [];
|
||||
for ($i=0; $i<5; $i++) {
|
||||
for ($i = 0; $i<5; $i++) {
|
||||
$parts[] = strtoupper(str_random(4));
|
||||
}
|
||||
return join('-', $parts);
|
||||
|
||||
return implode('-', $parts);
|
||||
}
|
||||
|
||||
public static function lookupEventId($eventName)
|
||||
{
|
||||
if ($eventName == 'create_client') {
|
||||
return EVENT_CREATE_CLIENT;
|
||||
} else if ($eventName == 'create_invoice') {
|
||||
} elseif ($eventName == 'create_invoice') {
|
||||
return EVENT_CREATE_INVOICE;
|
||||
} else if ($eventName == 'create_quote') {
|
||||
} elseif ($eventName == 'create_quote') {
|
||||
return EVENT_CREATE_QUOTE;
|
||||
} else if ($eventName == 'create_payment') {
|
||||
} elseif ($eventName == 'create_payment') {
|
||||
return EVENT_CREATE_PAYMENT;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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 ';
|
||||
}
|
||||
|
||||
|
@ -58,13 +58,11 @@ $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;
|
||||
}
|
||||
});
|
||||
|
@ -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>
|
||||
|
@ -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> </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> </p>
|
||||
<p> </p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@stop
|
Loading…
x
Reference in New Issue
Block a user