yf_manage_shop_send_sms admin module

Fileplugins/shop/admin_modules/manage_shop/yf_manage_shop_send_sms.class.php
Useadmin URL ?object=manage_shop_send_sms

Public properties

PropertyDefaultDescription
None declared in this class.

Public methods 1

send_sms

public function send_sms()
    public function send_sms()
    {
        if (main()->is_post()) {
            $phone = ($_POST['phone'] ?? null);
            $text = mb_substr(($_POST['text'] ?? ''), 0, 512);

            $turbosms = mysqli_connect(SMS_HOST, SMS_USER, SMS_PASS, SMS_NAME);
            if ( ! $turbosms) {
                return 'SMS gateway connection failed';
            }
            mysqli_set_charset($turbosms, 'utf8');

            if (strlen($phone) == 10) {
                $phone = '+38' . $phone;
            }
            if (strlen($phone) == 9) {
                $phone = '+380' . $phone;
            }

            $sql_sms_user = 'INSERT INTO ' . SMS_USER . " ( `sign`, `number`, `message` ) VALUES ( '" . mysqli_real_escape_string($turbosms, SMS_SIGN) . "', '" . mysqli_real_escape_string($turbosms, $phone) . "', '" . mysqli_real_escape_string($turbosms, $text) . "') ";
            mysqli_query($turbosms, $sql_sms_user);

            mysqli_close($turbosms);

            return 'SMS was sent';
        }

        $replace = null;
        if ( ! empty($_GET['phone'])) {
            $replace['phone'] = ($_GET['phone'] ?? null);
        }
        return form2($replace)
            ->text('phone', ['required' => 1])
            ->textarea('text', ['required' => 1])
            ->save(['value' => 'Send sms']);
    }