function edit_coupon_form($id) { global $LANG; if ($GLOBALS['me']) { if ($GLOBALS['me']->Stores > 0) { $coupon = \query\main::item_infos($id); if ($coupon->userID !== $GLOBALS['me']->ID) { return '<div class="info_form">' . $LANG['edit_cou_cant'] . '</div>'; } $form = '<div class="edit_coupon_form other_form">'; if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit_coupon_form']) && \site\utils::check_csrf($_POST['edit_coupon_form']['csrf'], 'edit_coupon_csrf')) { $pd = \site\utils::validate_user_data($_POST['edit_coupon_form']); try { \user\main::edit_coupon($id, $GLOBALS['me']->ID, $pd); $form .= '<div class="success">' . $LANG['edit_cou_success'] . '</div>'; } catch (Exception $e) { $form .= '<div class="error">' . $e->getMessage() . '</div>'; } } $csrf = $_SESSION['edit_coupon_csrf'] = \site\utils::str_random(12); $form .= '<form method="POST" action="#"> <div class="form_field"><label for="edit_coupon_form[store]">' . $LANG['submit_cou_addto'] . ':</label> <div><select name="edit_coupon_form[store]" id="edit_coupon_form[store]">'; foreach (stores_custom(array('user' => $GLOBALS['me']->ID, 'max' => 0)) as $v) { $form .= '<option value="' . $v->ID . '"' . (!isset($pd['store']) && $coupon->storeID == $v->ID || isset($pd['store']) && $pd['store'] == $v->ID ? ' selected' : '') . '>' . $v->name . '</option>'; } $form .= '</select></div> </div> <div class="form_field"><label for="edit_coupon_form[name]">' . $LANG['form_name'] . ':</label> <div><input type="text" name="edit_coupon_form[name]" id="edit_coupon_form[name]" value="' . (isset($pd['name']) ? $pd['name'] : $coupon->title) . '" placeholder="' . $LANG['submit_cou_name_ph'] . '" required /></div></div> <div class="form_field"><label for="edit_coupon_form[code]">' . $LANG['form_code'] . ':</label> <div><input type="text" name="edit_coupon_form[code]" id="edit_coupon_form[code]" value="' . (isset($pd['code']) ? $pd['code'] : $coupon->code) . '" placeholder="' . $LANG['submit_cou_code_ph'] . '" /></div></div> <div class="form_field"><label for="edit_coupon_form[url]">' . $LANG['form_coupon_url'] . ':</label> <div><input type="text" name="edit_coupon_form[url]" id="edit_coupon_form[url]" value="' . (isset($pd['url']) ? $pd['url'] : $coupon->url) . '" placeholder="' . $LANG['submit_cou_url_ph'] . '" /></div></div> <div class="form_field"><label for="edit_coupon_form[description]">' . $LANG['form_description'] . ':</label> <div><textarea name="edit_coupon_form[description]" id="edit_coupon_form[description]" style="height:100px;">' . (isset($pd['description']) ? $pd['description'] : $coupon->description) . '</textarea></div></div> <div class="form_field"><label for="edit_coupon_form[tags]">' . $LANG['form_tags'] . ':</label> <div><input type="text" name="edit_coupon_form[tags]" id="edit_coupon_form[tags]" value="' . (isset($pd['tags']) ? $pd['tags'] : $coupon->tags) . '" /></div></div> <div class="form_field"><label for="edit_coupon_form[start]">' . $LANG['form_start_date'] . ':</label> <div><input type="date" name="edit_coupon_form[start]" id="edit_coupon_form[start]" value="' . (isset($pd['start']) ? $pd['start'] : date('Y-m-d', strtotime($coupon->start_date))) . '" style="width: 79%; margin-right: 1%;" /><input type="time" name="edit_coupon_form[start_hour]" value="' . (isset($pd['start_hour']) ? $pd['start_hour'] : date('H:i', strtotime($coupon->start_date))) . '" style="width: 20%" /></div></div> <div class="form_field"><label for="edit_coupon_form[end]">' . $LANG['form_end_date'] . ':</label> <div><input type="date" name="edit_coupon_form[end]" id="edit_coupon_form[end]" value="' . (isset($pd['end']) ? $pd['end'] : date('Y-m-d', strtotime($coupon->expiration_date))) . '" style="width: 79%; margin-right: 1%;" /><input type="time" name="edit_coupon_form[end_hour]" value="' . (isset($pd['end_hour']) ? $pd['end_hour'] : date('H:i', strtotime($coupon->expiration_date))) . '" style="width: 20%" /></div></div> <input type="hidden" name="edit_coupon_form[csrf]" value="' . $csrf . '" /> <button>' . $LANG['edit_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>'; } }