Completed
Push — master ( 67bb37...e20777 )
by Michael
02:35
created

sendfriend.php (3 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
include_once __DIR__ . '/header.php';
23
require XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
24
//include XOOPS_ROOT_PATH . '/modules/adslight/class/utilities.php';
25
26
/**
27
 * @param $lid
28
 */
29
function SendFriend($lid)
30
{
31
    global $xoopsConfig, $xoopsDB, $xoopsTheme, $xoopsLogger, $moduleDirName, $main_lang;
32
33
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
34
    include XOOPS_ROOT_PATH . '/header.php';
35
    $xoTheme->addMeta('meta', 'robots', 'noindex, nofollow');
0 ignored issues
show
The variable $xoTheme does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
37
    $result = $xoopsDB->query('SELECT lid, title, type FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE lid={$lid}");
38
    list($lid, $title, $type) = $xoopsDB->fetchRow($result);
39
40
    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg4'><td valign='top'>
41
        <strong>" . _ADSLIGHT_SENDTO . " $lid \"<strong>$type : $title</strong>\" " . _ADSLIGHT_FRIEND . "<br><br>
42
        <form action=\"sendfriend.php\" method=post>
43
        <input type=\"hidden\" name=\"lid\" value=\"$lid\" />";
44
45
    if ($GLOBALS['xoopsUser'] instanceof XoopsUser) {
46
        $idd  = $GLOBALS['xoopsUser']->getVar('uname', 'E');
47
        $idde = $GLOBALS['xoopsUser']->getVar('email', 'E');
48
    }
49
50
    echo "
51
    <table width='99%' class='outer' cellspacing='1'>
52
    <tr>
53
      <td class='head' width='30%'>" . _ADSLIGHT_NAME . " </td>
54
      <td class='even'><input class='textbox' type='text' name='yname' value='$idd' /></td>
0 ignored issues
show
The variable $idd 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...
55
    </tr>
56
    <tr>
57
      <td class='head'>" . _ADSLIGHT_MAIL . " </td>
58
      <td class='even'><input class='textbox' type='text' name='ymail' value='$idde' /></td>
0 ignored issues
show
The variable $idde 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...
59
    </tr>
60
    <tr>
61
      <td class='head'>" . _ADSLIGHT_NAMEFR . " </td>
62
      <td class='even'><input class='textbox' type='text' name='fname' /></td>
63
    </tr>
64
    <tr>
65
      <td class='head'>" . _ADSLIGHT_MAILFR . " </td>
66
      <td class='even'><input class='textbox' type='text' name='fmail' /></td>
67
    </tr>";
68
69 View Code Duplication
    if ($GLOBALS['xoopsModuleConfig']['adslight_use_captcha'] == '1') {
70
        echo "<tr><td class='head'>" . _ADSLIGHT_CAPTCHA . " </td><td class='even'>";
71
        $jlm_captcha = '';
72
        $jlm_captcha = new XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, 'xoopscaptcha', false);
73
        echo $jlm_captcha->render();
74
        echo '</td></tr>';
75
    }
76
77
    echo '</table><br>
78
    <input type=hidden name=op value=MailAd>
79
    <input type=submit value=' . _ADSLIGHT_SENDFR . '>
80
    </form></td></tr></table>';
81
}
82
83
/**
84
 * @param $lid
85
 * @param $yname
86
 * @param $ymail
87
 * @param $fname
88
 * @param $fmail
89
 */
90
function MailAd($lid, $yname, $ymail, $fname, $fmail)
91
{
92
    global $xoopsConfig, $xoopsTpl, $xoopsDB, $xoopsModule, $myts, $xoopsLogger, $moduleDirName, $main_lang;
93
94 View Code Duplication
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_captcha']) {
95
        xoops_load('xoopscaptcha');
96
        $xoopsCaptcha = XoopsCaptcha::getInstance();
97
        if (!$xoopsCaptcha->verify()) {
98
            redirect_header(XOOPS_URL . '/modules/adslight/index.php', 2, $xoopsCaptcha->getMessage());
99
        }
100
    }
101
102
    $result = $xoopsDB->query('SELECT lid, title, expire, type, desctext, tel, price, typeprice, date, email, submitter, town, country, photo FROM '
103
                              . $xoopsDB->prefix('adslight_listing')
104
                              . ' WHERE lid='
105
                              . $xoopsDB->escape($lid));
106
    list($lid, $title, $expire, $type, $desctext, $tel, $price, $typeprice, $date, $email, $submitter, $town, $country, $photo) = $xoopsDB->fetchRow($result);
107
108
    $title     = $myts->addSlashes($title);
109
    $expire    = $myts->addSlashes($expire);
110
    $type      = $myts->addSlashes($type);
111
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1, 1, 1);
112
    $tel       = $myts->addSlashes($tel);
113
    $price     = $myts->addSlashes($price);
114
    $typeprice = $myts->addSlashes($typeprice);
115
    $submitter = $myts->addSlashes($submitter);
116
    $town      = $myts->addSlashes($town);
117
    $country   = $myts->addSlashes($country);
118
119
    $tags                       = array();
120
    $tags['YNAME']              = stripslashes($yname);
121
    $tags['YMAIL']              = $ymail;
122
    $tags['FNAME']              = stripslashes($fname);
123
    $tags['FMAIL']              = $fmail;
124
    $tags['HELLO']              = _ADSLIGHT_HELLO;
125
    $tags['LID']                = $lid;
126
    $tags['LISTING_NUMBER']     = _ADSLIGHT_LISTING_NUMBER;
127
    $tags['TITLE']              = $title;
128
    $tags['TYPE']               = AdslightUtilities::getNameType($type);
129
    $tags['DESCTEXT']           = $desctext;
130
    $tags['PRICE']              = $price;
131
    $tags['TYPEPRICE']          = $typeprice;
132
    $tags['TEL']                = $tel;
133
    $tags['TOWN']               = $town;
134
    $tags['COUNTRY']            = $country;
135
    $tags['OTHER']              = '' . _ADSLIGHT_INTERESS . '' . $xoopsConfig['sitename'] . '';
136
    $tags['LISTINGS']           = XOOPS_URL . '/modules/adslight/';
137
    $tags['LINK_URL']           = XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid;
138
    $tags['THINKS_INTERESTING'] = _ADSLIGHT_MESSAGE;
139
    $tags['NO_MAIL']            = _ADSLIGHT_NOMAIL;
140
    $tags['YOU_CAN_VIEW_BELOW'] = _ADSLIGHT_YOU_CAN_VIEW_BELOW;
141
    $tags['WEBMASTER']          = _ADSLIGHT_WEBMASTER;
142
    $tags['NO_REPLY']           = _ADSLIGHT_NOREPLY;
143
    $subject                    = '' . _ADSLIGHT_SUBJET . ' ' . $xoopsConfig['sitename'] . '';
144
    $xoopsMailer                =& xoops_getMailer();
145
    $xoopsMailer->multimailer->isHTML(true);
146
    $xoopsMailer->useMail();
147
    $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/');
148
    $xoopsMailer->setTemplate('listing_send_friend.tpl');
149
    $xoopsMailer->setFromEmail($ymail);
150
    $xoopsMailer->setToEmails($fmail);
151
    $xoopsMailer->setSubject($subject);
152
    $xoopsMailer->assign($tags);
153
    $xoopsMailer->send();
154
    echo $xoopsMailer->getErrors();
155
156
    redirect_header('index.php', 3, _ADSLIGHT_ANNSEND);
157
}
158
159
##############################################################
160
$yname = XoopsRequest::getString('yname', '', 'POST');
161
$ymail = XoopsRequest::getString('ymail', '', 'POST');
162
$fname = XoopsRequest::getString('fname', '', 'POST');
163
$fmail = XoopsRequest::getString('fmail', '', 'POST');
164
165
$lid = XoopsRequest::getInt('lid', 0);
166
$op  = XoopsRequest::getString('op', '');
167
168 View Code Duplication
switch ($op) {
169
170
    case 'SendFriend':
171
        include XOOPS_ROOT_PATH . '/header.php';
172
        SendFriend($lid);
173
        include XOOPS_ROOT_PATH . '/footer.php';
174
        break;
175
176
    case 'MailAd':
177
        MailAd($lid, $yname, $ymail, $fname, $fmail);
178
        break;
179
180
    default:
181
        redirect_header('index.php', 1, ' ' . _RETURNANN . ' ');
182
        break;
183
184
}
185