Example #1
0
 private function getForm()
 {
     $request = $this->getRequest();
     $id = $request->getQuery('id');
     if ($id) {
         $info = Model_Sizes::get($id);
     }
     if ($request->getPost('size')) {
         $this->view->size = $request->getPost('size');
     } elseif (isset($info)) {
         $this->view->size = round($info['size'], 2);
     } else {
         $this->view->size = '';
     }
     if ($request->getPost('name')) {
         $this->view->name = $request->getPost('name');
     } elseif (isset($info)) {
         $this->view->name = $info['name'];
     } else {
         $this->view->name = '';
     }
 }
Example #2
0
 private function getForm()
 {
     $request = $this->getRequest();
     $url = '';
     if ($request->getQuery('filter_id')) {
         $url .= '&filter_id=' . $request->getQuery('filter_id');
     }
     if ($request->getQuery('filter_name')) {
         $url .= '&filter_name=' . $request->getQuery('filter_name');
     }
     if ($request->getQuery('filter_username')) {
         $url .= '&filter_username='******'filter_username');
     }
     if ($request->getQuery('filter_user_id')) {
         $url .= '&filter_user_id=' . $request->getQuery('filter_user_id');
     }
     if ($request->getQuery('filter_price')) {
         $url .= '&filter_price=' . $request->getQuery('filter_price');
     }
     if ($request->getQuery('filter_sales')) {
         $url .= '&filter_sales=' . $request->getQuery('filter_sales');
     }
     if ($request->getQuery('filter_profit')) {
         $url .= '&filter_profit=' . $request->getQuery('filter_profit');
     }
     if ($request->getQuery('filter_free_request')) {
         $url .= '&filter_free_request=' . $request->getQuery('filter_free_request');
     }
     if ($request->getQuery('filter_free_file')) {
         $url .= '&filter_free_file=' . $request->getQuery('filter_free_file');
     }
     if ($request->getQuery('filter_weekly')) {
         $url .= '&filter_weekly=' . $request->getQuery('filter_weekly');
     }
     if ($request->getQuery('sort')) {
         $url .= '&sort=' . $request->getQuery('sort');
     }
     if ($request->getQuery('order')) {
         $url .= '&order=' . $request->getQuery('order');
     }
     if ($request->getQuery('page')) {
         $url .= '&page=' . $request->getQuery('page');
     }
     $id = $request->getQuery('id');
     $info = Model_Items::getItem($id);
     if (!$info) {
         $this->redirect($this->getRequest()->getBaseUrl() . $this->getRequest()->getModule() . '/items/?' . $url);
     }
     $this->view->cancel = $this->getRequest()->getBaseUrl() . $this->getRequest()->getModule() . '/items/?' . $url;
     $model_images = new Model_Images();
     $info['thumbnail'] = $model_images->resize($info['thumbnail'], JO_Registry::forceGet($info['module'] . '_items_thumb_width'), JO_Registry::forceGet($info['module'] . '_items_thumb_height'), true);
     if ((int) JO_Registry::get($info['module'] . '_items_preview_width') && (int) JO_Registry::get($info['module'] . '_items_preview_height')) {
         $info['theme_preview_thumbnail'] = $model_images->resize($info['theme_preview_thumbnail'], JO_Registry::forceGet($info['module'] . '_items_preview_width'), JO_Registry::forceGet($info['module'] . '_items_preview_height'), true);
     } elseif ((int) JO_Registry::get($info['module'] . '_items_preview_width')) {
         $info['theme_preview_thumbnail'] = $model_images->resizeWidth($info['theme_preview_thumbnail'], JO_Registry::forceGet($info['module'] . '_items_preview_width'));
     } elseif ((int) JO_Registry::get($info['module'] . '_items_preview_height')) {
         $info['theme_preview_thumbnail'] = $model_images->resizeHeight($info['theme_preview_thumbnail'], JO_Registry::forceGet($info['module'] . '_items_preview_height'));
     } else {
         $info['theme_preview_thumbnail'] = false;
     }
     $this->view->info = $info;
     $this->view->price_f = WM_Currency::format($info['suggested_price']);
     $this->view->categories = Model_Categories::getCategoriesFromParentByModule(0, $info['module']);
     $cats_module = Model_Categories::getCategories(array('filter_sub_of' => 0, 'filter_module' => $info['module'], 'filter_concat' => true));
     $where_attr = '';
     if ($cats_module) {
         $tmp = array();
         foreach ($cats_module as $c) {
             $tmp[] = "categories LIKE '%," . $c . ",%'";
         }
         if ($tmp) {
             $where_attr = implode(' OR ', $tmp);
         }
     }
     $this->view->attributes_list = array();
     $attr_cat = Model_Attributes::getAttributes(array(), $where_attr);
     if ($attr_cat) {
         foreach ($attr_cat as $row => $attr) {
             $attr_list = Model_Attributes::getAttributes(array('filter_sub_of' => $attr['id']));
             if ($attr_list) {
                 $this->view->attributes_list[$row] = $attr;
                 $this->view->attributes_list[$row]['items'] = $attr_list;
             }
         }
     }
     //var_dump($this->view->attributes_list);
     if ($request->getPost('name')) {
         $this->view->name = $request->getPost('name');
     } else {
         $this->view->name = $info['name'];
     }
     if ($request->getPost('description')) {
         $this->view->description = $request->getPost('description');
     } else {
         $this->view->description = $info['description'];
     }
     if ($request->getPost('price')) {
         $this->view->price = $request->getPost('price');
     } else {
         $this->view->price = $info['price'];
     }
     if ($request->getPost('category_id')) {
         $this->view->category_id = $request->getPost('category_id');
     } else {
         $this->view->category_id = Model_Items::getItemCategory($id);
     }
     if ($request->getPost('attributes')) {
         $this->view->attributes = $request->getPost('attributes');
     } else {
         $this->view->attributes = Model_Items::getItemAttributes($id);
     }
     if ($request->getPost('tags')) {
         $this->view->tags = $request->getPost('tags');
     } else {
         $this->view->tags = Model_Items::getItemTags($id);
     }
     if ($request->getPost('free_file')) {
         $this->view->free_file = $request->getPost('free_file');
     } else {
         $this->view->free_file = $info['free_file'];
     }
     if ($request->getPost('demo_url')) {
         $this->view->demo_url = $request->getPost('demo_url');
     } else {
         $this->view->demo_url = $info['demo_url'];
     }
     if ($request->getPost('weekly_from')) {
         $this->view->weekly_from = $request->getPost('weekly_from');
     } else {
         if ($info['weekly_from'] != '0000-00-00') {
             $this->view->weekly_from = JO_Date::getInstance($info['weekly_from'], 'dd.mm.yy', true)->toString();
         } else {
             $this->view->weekly_from = '';
         }
     }
     if ($request->getPost('weekly_to')) {
         $this->view->weekly_to = $request->getPost('weekly_to');
     } else {
         if ($info['weekly_to'] != '0000-00-00') {
             $this->view->weekly_to = JO_Date::getInstance($info['weekly_to'], 'dd.mm.yy', true)->toString();
         } else {
             $this->view->weekly_to = '';
         }
     }
     if ($request->getPost('default_price')) {
         $this->view->default_price = $request->getPost('default_price');
     } else {
         $this->view->default_price = '';
     }
     /* sizes */
     $prices = Model_Items_Image::getPriceItem($id);
     $sizes = Model_Sizes::getAll();
     $this->view->sizes = array();
     if ($sizes) {
         $filesize = false;
         if ($info['main_file'] && file_exists(BASE_PATH . '/uploads/' . $info['main_file'])) {
             $info_file = getimagesize(BASE_PATH . '/uploads/' . $info['main_file']);
             $filesize = $info_file[0] * $info_file[1];
         }
         foreach ($sizes as $k => $size) {
             $price = isset($prices[$size['id']]) ? $prices[$size['id']] : '';
             if ($filesize && $size['size'] * 1000000 <= $filesize) {
                 $size['post_price'] = $request->issetPost('price[' . $size['id'] . ']') ? $request->getPost('price[' . $size['id'] . ']') : $price;
                 $size['size'] = round($size['size'], 2);
                 $this->view->sizes[$k] = $size;
                 $this->view->default_price = $this->view->default_price ? $this->view->default_price : ($size['post_price'] == $info['price'] ? $size['id'] : '');
             }
         }
         if (!$this->view->default_price) {
             foreach ($sizes as $k => $size) {
                 if ($filesize && $size['size'] * 1000000 <= $filesize) {
                     $this->view->default_price = $size['id'];
                     break;
                 }
             }
         }
     }
 }
Example #3
0
File: Image.php Project: noikiy/PD
    public function editItem($id, $data)
    {
        set_time_limit(0);
        $db = JO_Db::getDefaultAdapter();
        $info = self::getItem($id);
        if (!$info) {
            return;
        }
        if (isset($data['free_file'])) {
            $db->update('items', array('free_file' => 'false'));
            self::addUserStatus($id, 'freefile');
        }
        $db->update('items', array('name' => $data['name'], 'description' => $data['description'], 'price' => $data['price'][$data['default_price']], 'free_file' => isset($data['free_file']) ? 'true' : 'false', 'item_tags_string' => isset($data['tags']) ? $data['tags'] : '', 'weekly_from' => $data['weekly_from'] ? JO_Date::getInstance($data['weekly_from'], 'yy-mm-dd', true) : '0000-00-00', 'weekly_to' => $data['weekly_to'] ? JO_Date::getInstance($data['weekly_to'], 'yy-mm-dd', true) : '0000-00-00'), array('id = ?' => (int) $id));
        if (isset($data['set_status']) && $data['set_status'] == 'active') {
            $db->update('items', array('status' => $data['set_status']), array('id = ?' => (int) $id));
            /////////// send email
            $request = JO_Request::getInstance();
            $translate = JO_Translate::getInstance();
            $not_template = Model_Notificationtemplates::get('approval_item');
            $mail = new JO_Mail();
            if (JO_Registry::get('mail_smtp')) {
                $mail->setSMTPParams(JO_Registry::forceGet('mail_smtp_host'), JO_Registry::forceGet('mail_smtp_port'), JO_Registry::forceGet('mail_smtp_user'), JO_Registry::forceGet('mail_smtp_password'));
            }
            $mail->setFrom('no-reply@' . $request->getDomain());
            $href = '<a href="' . WM_Router::create($request->getBaseUrl() . '?controller=items&item_id=' . $id) . '">' . $info['name'] . '</a>';
            if ($not_template) {
                $title = $not_template['title'];
                $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                $html = str_replace('{USERNAME}', $info['username'], $html);
                $html = str_replace('{ITEM}', $info['name'], $html);
                $html = str_replace('{URL}', $href, $html);
            } else {
                $title = "[" . $request->getDomain() . "] " . $data['name'];
                $html = nl2br($translate->translate('Item') . ' 
				' . $href . ' ' . $translate->translate('approval'));
            }
            $mail->setSubject($title);
            $mail->setHTML($html);
            $result = $mail->send(array($info['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
            unset($mail);
            //////////////////////
        }
        if (isset($data['weekly_to']) && trim($data['weekly_to']) != '') {
            self::addUserStatus($id, 'featured');
        }
        $db->delete('items_to_category', array('item_id = ?' => (int) $id));
        if (isset($data['category_id'])) {
            foreach ($data['category_id'] as $category_id) {
                $categories = Model_Categories::getCategoryParents(Model_Categories::getCategories(array('filter_id_key' => true)), $category_id);
                $categories = explode(',', $categories);
                array_pop($categories);
                $categories = array_reverse($categories);
                $categories = ',' . implode(',', $categories) . ',';
                $db->insert('items_to_category', array('item_id' => (int) $id, 'categories' => $categories));
            }
        }
        $db->delete('items_attributes', array('item_id = ?' => (int) $id));
        if (isset($data['attributes']) && is_array($data['attributes'])) {
            foreach ($data['attributes'] as $cid => $value) {
                if (is_array($value)) {
                    foreach ($value as $val) {
                        $db->insert('items_attributes', array('item_id' => $id, 'attribute_id' => $val, 'category_id' => (int) $cid));
                    }
                } elseif ($value) {
                    $db->insert('items_attributes', array('item_id' => $id, 'attribute_id' => $value, 'category_id' => (int) $cid));
                }
            }
        }
        $db->delete('items_tags', array('item_id = ?' => (int) $id));
        if (isset($data['tags']) && $data['tags']) {
            $tags = explode(',', $data['tags']);
            foreach ($tags as $tag) {
                $tag = trim($tag);
                if ($tag) {
                    $tag_id = Model_Tags::getTagByTitleAndInsert($tag);
                    if ($tag_id) {
                        $db->insert('items_tags', array('item_id' => $id, 'tag_id' => (int) $tag_id, 'type' => ''));
                    }
                }
            }
        }
        $sizes = Model_Sizes::getAll();
        $tmp_sizes = array();
        foreach ($sizes as $size1) {
            $tmp_sizes[$size1['id']] = $size1;
        }
        $info_file = getimagesize(BASE_PATH . '/uploads/' . $info['main_file']);
        $steps = 0;
        if ($info_file[0] < $info_file[1]) {
            $type = 'p';
            $steps = $info_file[0];
            $source_aspect_ratio = round($info_file[1] / $info_file[0], 5);
        } elseif ($info_file[0] > $info_file[1]) {
            $type = 'l';
            $steps = $info_file[1];
            $source_aspect_ratio = round($info_file[0] / $info_file[1], 5);
        } else {
            $type = 'k';
            $steps = $info_file[0];
            $source_aspect_ratio = 1;
        }
        $temp_sizes = array();
        $temp_sizes2 = array();
        $deleted = array();
        foreach ($data['price'] as $size_id => $price) {
            if (trim($price) && (double) $price && isset($tmp_sizes[$size_id])) {
                $sizeMP = $tmp_sizes[$size_id]['size'] * 1000000;
                $sizeMPFrom = $sizeMP - $sizeMP / 100;
                for ($i = $steps; $i >= 1; $i--) {
                    if ($type == 'p') {
                        $width = $info_file[0] - $i;
                        $height = round($width * $source_aspect_ratio);
                    } elseif ($type == 'l') {
                        $height = $info_file[1] - $i;
                        $width = round($height * $source_aspect_ratio);
                    } else {
                        $width = $info_file[0] - $i;
                        $height = $info_file[1] - $i;
                    }
                    if ($width < 1 || $height < 1) {
                        continue;
                    }
                    if ($width * $height >= $sizeMPFrom && $width * $height <= $sizeMP) {
                        $temp_sizes[$size_id] = array('width' => $width, 'height' => $height, 'price' => $price, 'size_id' => $size_id, 'size' => $tmp_sizes[$size_id]['size']);
                        $temp_sizes2[$size_id] = true;
                        continue;
                    }
                }
            } else {
                $deleted[] = $size_id;
            }
        }
        $query_files = $db->select()->from('items_prices')->where('item_id = ?', (int) $id);
        $list_files = $db->fetchAll($query_files);
        if ($list_files) {
            foreach ($list_files as $fils) {
                if (in_array($fils['size_id'], $deleted)) {
                    if (!self::fileIsOrdered($id, $fils['size_id'])) {
                        unlink(BASE_PATH . '/uploads/' . $fils['main_file']);
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    } else {
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    }
                } elseif (!in_array($fils['size_id'], $temp_sizes2)) {
                    if (!self::fileIsOrdered($id, $fils['size_id'])) {
                        unlink(BASE_PATH . '/uploads/' . $fils['main_file']);
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    } else {
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    }
                } else {
                    if (file_exists(BASE_PATH . '/uploads/' . $fils['main_file'])) {
                        $db->update('items_prices', array('price' => (double) $temp_sizes[$fils['size_id']]['price']), array('id = ?' => (int) $fils['id']));
                        unset($temp_sizes[$fils['size_id']]);
                    } else {
                        $db->delete('items_prices', array('id = ?' => (int) $fils['id']));
                    }
                }
            }
        }
        $main_file = BASE_PATH . '/uploads/' . $info['main_file'];
        $main_path = dirname($info['main_file']);
        foreach ($temp_sizes as $key => $value) {
            $name_new = md5(time() . '_' . mt_rand()) . '.' . round($key, 2) . strtolower(strrchr(basename($info['main_file']), '.'));
            $ext = strtolower(strrchr($info['main_file'], '.'));
            $image_p = imagecreatetruecolor($value['width'], $value['height']);
            $image = null;
            if ($ext == '.jpg' || $ext == '.jpeg') {
                $image = imagecreatefromjpeg(BASE_PATH . '/uploads/' . $info['main_file']);
            } else {
                continue;
            }
            imageantialias($image_p, true);
            if ($image) {
                imagecopyresampled($image_p, $image, 0, 0, 0, 0, $value['width'], $value['height'], $info_file[0], $info_file[1]);
            }
            if (!file_exists(dirname($main_file) . '/downloads/')) {
                mkdir(dirname($main_file) . '/downloads/', 0777, true);
            }
            imagejpeg($image_p, dirname($main_file) . '/downloads/' . $name_new, 100);
            if (file_exists(dirname($main_file) . '/downloads/' . $name_new)) {
                $db->insert('items_prices', array('item_id' => (int) $id, 'size_id' => (int) $value['size_id'], 'price' => (double) $value['price'], 'main_file' => $main_path . '/downloads/' . $name_new, 'size' => $key, 'width' => $value['width'], 'height' => $value['height']));
            }
        }
    }