示例#1
0
function edit_product_form($id)
{
    global $LANG;
    if ($GLOBALS['me']) {
        if ($GLOBALS['me']->Stores > 0) {
            $product = \query\main::product_infos($id);
            if ($product->userID !== $GLOBALS['me']->ID) {
                return '<div class="info_form">' . $LANG['edit_prod_cant'] . '</div>';
            }
            /* */
            $product_image = $product->image;
            $form = '<div class="edit_product_form other_form">';
            if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit_product_form']) && \site\utils::check_csrf($_POST['edit_product_form']['csrf'], 'edit_coupon_csrf')) {
                $pd = \site\utils::validate_user_data($_POST['edit_product_form']);
                try {
                    $post_info = \user\main::edit_product($id, $GLOBALS['me']->ID, $pd);
                    $product_image = $post_info->image;
                    $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="#" enctype="multipart/form-data">
  <div class="form_field"><label for="edit_product_form[store]">' . $LANG['submit_prod_addto'] . ':</label>
  <div><select name="edit_product_form[store]" id="edit_product_form[store]">';
            foreach (stores_custom(array('user' => $GLOBALS['me']->ID, 'max' => 0)) as $v) {
                $form .= '<option value="' . $v->ID . '"' . (!isset($pd['store']) && $product->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_product_form[name]">' . $LANG['form_name'] . ':</label> <div><input type="text" name="edit_product_form[name]" id="edit_product_form[name]" value="' . (isset($pd['name']) ? $pd['name'] : $product->title) . '" placeholder="' . $LANG['submit_prod_name_ph'] . '" required /></div></div>
  <div class="form_field"><label for="edit_product_form[price]">' . $LANG['form_price'] . ':</label> <div><input type="text" name="edit_product_form[price]" id="edit_product_form[price]" value="' . (isset($pd['price']) ? $pd['price'] : (empty($product->price) ? '' : $product->price)) . '" placeholder="' . $LANG['submit_prod_price_ph'] . '" /></div></div>
  <div class="form_field"><label for="edit_product_form[old_price]">' . $LANG['form_old_price'] . ':</label> <div><input type="text" name="edit_product_form[old_price]" id="edit_product_form[old_price]" value="' . (isset($pd['old_price']) ? $pd['old_price'] : (empty($product->old_price) ? '' : $product->old_price)) . '" placeholder="' . $LANG['submit_prod_oldprice_ph'] . '" /></div></div>
  <div class="form_field"><label for="edit_product_form[currency]">' . $LANG['form_currency'] . ':</label> <div><input type="text" name="edit_product_form[currency]" id="edit_product_form[currency]" value="' . (isset($pd['currency']) ? $pd['currency'] : $product->currency) . '" /></div></div>
  <div class="form_field"><label for="edit_product_form[url]">' . $LANG['form_product_url'] . ':</label> <div><input type="text" name="edit_product_form[url]" id="edit_product_form[url]" value="' . (isset($pd['url']) ? $pd['url'] : $product->url) . '" placeholder="' . $LANG['submit_cou_url_ph'] . '" /></div></div>
  <div class="form_field"><label for="edit_product_form[description]">' . $LANG['form_description'] . ':</label> <div><textarea name="edit_product_form[description]" id="edit_product_form[description]" style="height:100px;">' . (isset($pd['description']) ? $pd['description'] : $product->description) . '</textarea></div></div>
  <div class="form_field"><label for="edit_product_form[tags]">' . $LANG['form_tags'] . ':</label> <div><input type="text" name="edit_product_form[tags]" id="edit_product_form[tags]" value="' . (isset($pd['tags']) ? $pd['tags'] : $product->tags) . '" /></div></div>
  <div class="form_field"><label for="edit_product_form_image">' . $LANG['form_image'] . ':</label> <div><img src="' . product_avatar($product_image) . '" alt="" style="width:90px; height:90px;" /> <input type="file" name="edit_product_form_image" id="edit_product_form_image" />
  <span>Note:* max width: 800px, max height: 800px.</span></div></div>
  <div class="form_field"><label for="edit_product_form[start]">' . $LANG['form_start_date'] . ':</label> <div><input type="date" name="edit_product_form[start]" id="edit_product_form[start]" value="' . (isset($pd['start']) ? $pd['start'] : date('Y-m-d', strtotime($product->start_date))) . '" style="width: 79%; margin-right: 1%;" /><input type="time" name="edit_product_form[start_hour]" value="' . (isset($pd['start_hour']) ? $pd['start_hour'] : date('H:i', strtotime($product->start_date))) . '" style="width: 20%" /></div></div>
  <div class="form_field"><label for="edit_product_form[end]">' . $LANG['form_end_date'] . ':</label> <div><input type="date" name="edit_product_form[end]" id="edit_product_form[end]" value="' . (isset($pd['end']) ? $pd['end'] : date('Y-m-d', strtotime($product->expiration_date))) . '" style="width: 79%; margin-right: 1%;" /><input type="time" name="edit_product_form[end_hour]" value="' . (isset($pd['end_hour']) ? $pd['end_hour'] : date('H:i', strtotime($product->expiration_date))) . '" style="width: 20%" /></div></div>
  <input type="hidden" name="edit_product_form[csrf]" value="' . $csrf . '" />
  <button>' . $LANG['edit_prod_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>';
    }
}