function submit_coupon_form($auto_select = array('store' => '')) { global $LANG; if ($GLOBALS['me']) { if ($GLOBALS['me']->Stores > 0) { if (!(bool) \query\main::get_option('allow_coupons')) { return '<div class="info_form">' . $LANG['submit_cou_not_allowed'] . '</div>'; } $form = '<div class="submit_coupon_form other_form">'; if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit_coupon_form']) && \site\utils::check_csrf($_POST['submit_coupon_form']['csrf'], 'submit_coupon_csrf')) { $pd = \site\utils::validate_user_data($_POST['submit_coupon_form']); try { \user\main::submit_coupon($GLOBALS['me']->ID, $pd); $form .= '<div class="success">' . $LANG['submit_cou_success'] . '</div>'; unset($pd); } catch (Exception $e) { $form .= '<div class="error">' . $e->getMessage() . '</div>'; } } $csrf = $_SESSION['submit_coupon_csrf'] = \site\utils::str_random(12); $form .= '<form method="POST" action="#"> <div class="form_field"><label for="submit_coupon_form[store]">' . $LANG['submit_cou_addto'] . '</label> <div><select name="submit_coupon_form[store]" id="submit_coupon_form[store]">'; foreach (stores_custom(array('user' => $GLOBALS['me']->ID, 'max' => 0)) as $v) { $form .= '<option value="' . $v->ID . '"' . (!isset($pd['store']) && !empty($auto_select['store']) && ($auto_select['store'] == $v->ID || $auto_select['store'] == $v->name) || isset($pd['store']) && $pd['store'] == $v->ID ? ' selected' : '') . '>' . $v->name . '</option>'; } $form .= '</select></div> </div> <div class="form_field"><label for="submit_coupon_form[name]">' . $LANG['form_name'] . ':</label> <div><input type="text" name="submit_coupon_form[name]" id="submit_coupon_form[name]" value="' . (isset($pd['name']) ? $pd['name'] : '') . '" placeholder="' . $LANG['submit_cou_name_ph'] . '" required /></div></div> <div class="form_field"><label for="submit_coupon_form[code]">' . $LANG['form_code'] . ':</label> <div><input type="text" name="submit_coupon_form[code]" id="submit_coupon_form[code]" value="' . (isset($pd['code']) ? $pd['code'] : '') . '" placeholder="' . $LANG['submit_cou_code_ph'] . '" /></div></div> <div class="form_field"><label for="submit_coupon_form[url]">' . $LANG['form_coupon_url'] . ':</label> <div><input type="text" name="submit_coupon_form[url]" id="submit_coupon_form[url]" value="' . (isset($pd['url']) ? $pd['url'] : '') . '" placeholder="' . $LANG['submit_cou_url_ph'] . '" /></div></div> <div class="form_field"><label for="submit_coupon_form[description]">' . $LANG['form_description'] . ':</label> <div><textarea name="submit_coupon_form[description]" id="submit_coupon_form[description]" style="height:100px;">' . (isset($pd['description']) ? $pd['description'] : '') . '</textarea></div></div> <div class="form_field"><label for="submit_coupon_form[tags]">' . $LANG['form_tags'] . ':</label> <div><input type="text" name="submit_coupon_form[tags]" id="submit_coupon_form[tags]" value="' . (isset($pd['tags']) ? $pd['tags'] : '') . '" /></div></div> <div class="form_field"><label for="submit_coupon_form[start]">' . $LANG['form_start_date'] . ':</label> <div><input type="date" name="submit_coupon_form[start]" id="submit_coupon_form[start]" value="' . (isset($pd['start']) ? $pd['start'] : '') . '" style="width: 79%; margin-right: 1%;" /><input type="time" name="submit_coupon_form[start_hour]" value="' . (isset($pd['start_hour']) ? $pd['start_hour'] : '00:00') . '" style="width: 20%" /></div></div> <div class="form_field"><label for="submit_coupon_form[end]">' . $LANG['form_end_date'] . ':</label> <div><input type="date" name="submit_coupon_form[end]" id="submit_coupon_form[end]" value="' . (isset($pd['end']) ? $pd['end'] : '') . '" style="width: 79%; margin-right: 1%;" /><input type="time" name="submit_coupon_form[end_hour]" value="' . (isset($pd['end_hour']) ? $pd['end_hour'] : '00:00') . '" style="width: 20%" /></div></div> <input type="hidden" name="submit_coupon_form[csrf]" value="' . $csrf . '" /> <button>' . $LANG['submit_cou_button'] . '</button> </form> </div>'; return $form; } else { return '<div class="info_form">' . $LANG['unavailable_form2'] . '</div>'; } } else { return '<div class="info_form">' . $LANG['unavailable_form'] . '</div>'; } }