Пример #1
0
 private function getForm()
 {
     $request = $this->getRequest();
     $id = $request->getQuery('id');
     if ($id) {
         $info = Model_Notificationtemplates::get($id);
     }
     if ($request->getPost('title')) {
         $this->view->title = $request->getPost('title');
     } elseif (isset($info)) {
         $this->view->title = $info['title'];
     } else {
         $this->view->title = '';
     }
     if ($request->getPost('template')) {
         $this->view->template1 = $request->getPost('template');
     } elseif (isset($info)) {
         $this->view->template1 = $info['template'];
     } else {
         $this->view->template1 = '';
     }
     if (isset($info)) {
         $this->view->info = $info['info'];
     }
 }
Пример #2
0
 public static function createBulletin($data)
 {
     $db = JO_Db::getDefaultAdapter();
     $db->insert('bulletin', array('name' => $data['name'], 'text' => $data['text'], 'datetime' => new JO_Db_Expr('NOW()'), 'send_to' => $data['send_to'], 'send_id' => 0));
     $id = $db->lastInsertId();
     $emails = Model_Bulletinemails::getEmails(array('filter_bulletin_subscribe' => 'true'));
     $domain = JO_Request::getInstance()->getDomain();
     $send_to = 0;
     if ($emails) {
         foreach ($emails as $email) {
             $not_template = Model_Notificationtemplates::get('bulletin_email');
             $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@' . $domain);
             $mail->setSubject("[" . $domain . "] " . $data['name']);
             if ($not_template) {
                 $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                 $html = str_replace('{FIRSTNAME}', $email['firstname'], $html);
                 $html = str_replace('{LASTNAME}', $email['lastname'], $html);
                 $html = str_replace('{MESSAGE}', html_entity_decode($data['text'], ENT_QUOTES, 'utf-8'), $html);
             } else {
                 $html = html_entity_decode($data['text'], ENT_QUOTES, 'utf-8');
             }
             $mail->setHTML($html);
             $result = $mail->send(array($email['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
             if ($result) {
                 $send_to++;
             }
             unset($mail);
         }
     }
     $db->update('bulletin', array('readed' => $send_to), array('id = ?' => $id));
     return $id;
 }
Пример #3
0
    public function editItem($id, $data)
    {
        $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'], 'free_file' => isset($data['free_file']) ? 'true' : 'false', '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));
            $db->update(Model_Users::getPrefixDB() . 'users', array('items' => new JO_Db_Expr('items + 1')), array('user_id = ?' => $info['user_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() . '?module=' . $info['module'] . '&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' => ''));
                    }
                }
            }
        }
    }
Пример #4
0
 public static function deleteItem($id, $message = '')
 {
     $db = JO_Db::getDefaultAdapter();
     $info = self::getItem($id);
     if (!$info) {
         return;
     }
     $path = BASE_PATH . '/uploads/items/' . JO_Date::getInstance($info['datetime'], 'yy/mm/', true)->toString() . $id . '/';
     self::unlink($path);
     $db->delete('items', array('id = ?' => (int) $id));
     $db->delete('items_attributes', array('item_id = ?' => (int) $id));
     $db->delete('items_collections', array('item_id = ?' => (int) $id));
     $db->delete('items_comments', array('item_id = ?' => (int) $id));
     $db->delete('items_faqs', array('item_id = ?' => (int) $id));
     $db->delete('items_rates', array('item_id = ?' => (int) $id));
     $db->delete('items_tags', array('item_id = ?' => (int) $id));
     $db->delete('items_to_category', array('item_id = ?' => (int) $id));
     $db->update(Model_Users::getPrefixDB() . 'users', array('items' => new JO_Db_Expr('items - 1')), array('user_id = ?' => $info['user_id']));
     /////////// send email
     $request = JO_Request::getInstance();
     $translate = JO_Translate::getInstance();
     $not_template = Model_Notificationtemplates::get('delete_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());
     if ($not_template) {
         $user_info = Model_Users::getUser($info['user_id']);
         $title = $not_template['title'];
         $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
         $html = str_replace('{USERNAME}', $user_info['username'], $html);
         $html = str_replace('{ITEM}', $info['name'], $html);
         $html = str_replace('{MESSAGE}', $message, $html);
     } else {
         $title = "[" . $request->getDomain() . "] " . $info['name'];
         $html = nl2br($translate->translate('Item is deleted'));
     }
     $mail->setSubject($title);
     $mail->setHTML($html);
     $result = $mail->send(array($user_info['email']), JO_Registry::get('mail_smtp') ? 'smtp' : 'mail');
     unset($mail);
     //////////////////////
     self::deleteItemUpdate($id);
     self::unlink(BASE_PATH . '/uploads/items/' . JO_Date::getInstance($info['datetime'], 'yy/mm/', true)->toString() . $id . '/');
     self::unlink(BASE_PATH . '/uploads/cache/items/' . JO_Date::getInstance($info['datetime'], 'yy/mm/', true)->toString() . $id . '/');
     //		$info = self::getItemUpdate($id);
     //		if(!$info) {
     //			return;
     //		}
     //
     //		$db->delete('temp_items', array('item_id = ?' => (int)$id));
     //		$db->delete('temp_items_tags', array('item_id = ?' => (int)$id));
 }
Пример #5
0
    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']));
            }
        }
    }