Completed
Branch develop (caae7e)
by
unknown
25:30
created

stripe.lib.php ➔ stripeadmin_prepare_head()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) 2017      Alexandre Spangaro   <[email protected]>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
/**
19
 *	\file			htdocs/stripe/lib/stripe.lib.php
20
 *	\ingroup		stripe
21
 *  \brief			Library for common stripe functions
22
 */
23
24
/**
25
 *  Define head array for tabs of stripe tools setup pages
26
 *
27
 *  @return			Array of head
28
 */
29
function stripeadmin_prepare_head()
30
{
31
	global $langs, $conf;
32
33
	$h = 0;
34
	$head = array();
35
36
	$head[$h][0] = DOL_URL_ROOT."/stripe/admin/stripe.php";
37
	$head[$h][1] = $langs->trans("Stripe");
38
	$head[$h][2] = 'stripeaccount';
39
	$h++;
40
41
	$object=new stdClass();
42
43
    // Show more tabs from modules
44
    // Entries must be declared in modules descriptor with line
45
    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
46
    // $this->tabs = array('entity:-tabname);   												to remove a tab
47
	complete_head_from_modules($conf,$langs,$object,$head,$h,'stripeadmin');
48
49
	complete_head_from_modules($conf,$langs,$object,$head,$h,'stripeadmin','remove');
50
51
    return $head;
52
}
53
54
55
56
/**
57
 * Return string with full Url
58
 *
59
 * @param   string	$type		Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...)
60
 * @param	string	$ref		Ref of object
61
 * @return	string				Url string
62
 */
63
function showStripePaymentUrl($type,$ref)
64
{
65
	global $conf, $langs;
66
67
	$langs->load("paypal");
68
    $langs->load("paybox");
69
	$langs->load("stripe");
70
71
    $servicename='Stripe';
72
    $out='<br><br>';
73
    $out.=img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment",$servicename).'<br>';
74
    $url=getStripePaymentUrl(0,$type,$ref);
75
    $out.='<input type="text" id="stripeurl" class="quatrevingtpercent" value="'.$url.'"><br>';
76
    $out.=ajax_autoselect("stripeurl", 0);
77
    return $out;
78
}
79
80
/**
81
 * Return string with full Url
82
 *
83
 * @param   int		$mode		0=True url, 1=Url formated with colors
84
 * @param   string	$type		Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...)
85
 * @param	string	$ref		Ref of object
86
 * @param	int		$amount		Amount
87
 * @param	string	$freetag	Free tag
88
 * @return	string				Url string
89
 */
90
function getStripePaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag')
91
{
92
	global $conf;
93
94
	$ref=str_replace(' ','',$ref);
95
	
96
    if ($type == 'free')
97
    {
98
	    $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
99
    }
100
    if ($type == 'order')
101
    {
102
        $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
103
        if ($mode == 1) $out.='order_ref';
104
        if ($mode == 0) $out.=urlencode($ref);
105
	    $out.=($mode?'</font>':'');
106
    }
107
    if ($type == 'invoice')
108
    {
109
        $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
110
        if ($mode == 1) $out.='invoice_ref';
111
        if ($mode == 0) $out.=urlencode($ref);
112
	    $out.=($mode?'</font>':'');
113
    }
114
    if ($type == 'contractline')
115
    {
116
        $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
117
        if ($mode == 1) $out.='contractline_ref';
118
        if ($mode == 0) $out.=urlencode($ref);
119
	    $out.=($mode?'</font>':'');
120
    }
121
    if ($type == 'membersubscription')
122
    {
123
        $out=DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
124
        if ($mode == 1) $out.='member_ref';
125
        if ($mode == 0) $out.=urlencode($ref);
126
	    $out.=($mode?'</font>':'');
127
    }
128
129
    // For multicompany
130
    $out.="&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
0 ignored issues
show
Bug introduced by
The variable $out does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
131
132
    return $out;
133
}
134
135
136
/**
137
 * Show footer of company in HTML pages
138
 *
139
 * @param   Societe		$fromcompany	Third party
140
 * @param   Translate	$langs			Output language
141
 * @return	void
142
 */
143
function html_print_stripe_footer($fromcompany,$langs)
144
{
145
	global $conf;
146
147
	// Juridical status
148
	$line1="";
149
	if ($fromcompany->forme_juridique_code)
150
	{
151
		$line1.=($line1?" - ":"").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
152
	}
153
	// Capital
154
	if ($fromcompany->capital)
155
	{
156
		$line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
157
	}
158
	// Prof Id 1
159
	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
160
	{
161
		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
162
		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
163
		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
164
	}
165
	// Prof Id 2
166
	if ($fromcompany->idprof2)
167
	{
168
		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
169
		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
170
		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
171
	}
172
173
	// Second line of company infos
174
	$line2="";
175
	// Prof Id 3
176
	if ($fromcompany->idprof3)
177
	{
178
		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
179
		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
180
		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
181
	}
182
	// Prof Id 4
183
	if ($fromcompany->idprof4)
184
	{
185
		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
186
		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
187
		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
188
	}
189
	// IntraCommunautary VAT
190
	if ($fromcompany->tva_intra != '')
191
	{
192
		$line2.=($line2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
193
	}
194
195
	print '<br><br><hr>'."\n";
196
	print '<div class="center"><font style="font-size: 10px;">'."\n";
197
	print $fromcompany->name.'<br>';
198
	print $line1.'<br>';
199
	print $line2;
200
	print '</font></div>'."\n";
201
}
202
203