Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Digishop Class
- *
- * @package CMS Pro
- * @author wojoscripts.com
- * @copyright 2014
- * @version $Id: class_admin.php, v4.00 2014-10-01 16:10:25 gewa Exp $
- */
- if (!defined("_VALID_PHP"))
- die('Direct access to this location is not allowed.');
- class Digishop
- {
- const mTable = "mod_digishop";
- const ctTable = "mod_digishop_categories";
- const rTable = "mod_digishop_related_categories";
- const trTable = "mod_digishop_transactions";
- const xTable = "mod_digishop_cart";
- private $cattree = array();
- private $catlist = array();
- const imagepath = "modules/digishop/dataimages/";
- private static $db;
- /**
- * Digishop::__construct()
- *
- * @return
- */
- function __construct($ctree = true, $item = false, $cat = false)
- {
- self::$db = Registry::get("Database");
- $this->getConfig();
- $this->cattree = ($ctree) ? $this->getCatTree() : null;
- ($item) ? $this->renderSingleProduct() : null;
- ($cat) ? $this->renderSingleCategory() : null;
- }
- /**
- * Digishop::getConfig()
- *
- * @return
- */
- private function getConfig()
- {
- $row = INI::read(MODPATH . 'digishop/config.ini');
- $this->filedir = base64_decode($row->ds_config->filedir);
- $this->allow_free = $row->ds_config->allow_free;
- $this->cols = $row->ds_config->cols;
- $this->ipp = $row->ds_config->ipp;
- $this->fpp = $row->ds_config->fpp;
- $this->like = $row->ds_config->like;
- $this->layout = $row->ds_config->layout;
- $this->show_counter = $row->ds_config->show_counter;
- $this->template = base64_decode($row->ds_config->template);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::getCatTree()
- *
- * @return
- */
- protected function getCatTree()
- {
- $query = self::$db->query("SELECT * FROM " . self::ctTable . " ORDER BY parent_id, sorting");
- while ($row = self::$db->fetch($query)) {
- $this->cattree[$row->id] = array(
- 'id' => $row->id,
- 'name'.Lang::$lang => $row->{'name'.Lang::$lang},
- 'parent_id' => $row->parent_id
- );
- }
- return $this->cattree;
- }
- /**
- * Digishop::getCatList()
- *
- * @return
- */
- public function getCatList()
- {
- $query = self::$db->query("SELECT *, (SELECT COUNT(p.id) FROM " . self::mTable . " p"
- . "\n INNER JOIN " . self::rTable . " rc on p.id = rc.pid"
- . "\n WHERE rc.cid = " . self::ctTable . ".id AND p.active = 1) as totalitems"
- . "\n FROM " . self::ctTable
- . "\n ORDER BY parent_id, sorting");
- $res = self::$db->numrows($query);
- while ($row = self::$db->fetch($query)) {
- $catlist[$row->id] = array(
- 'id' => $row->id,
- 'slug' => $row->slug,
- 'name'.Lang::$lang => $row->{'name'.Lang::$lang},
- 'parent_id' => $row->parent_id,
- 'totalitems'=> $row->totalitems
- );
- }
- return ($res) ? $catlist : null;
- }
- /**
- * Digishop::getCatCheckList()
- *
- * @param mixed $parent_id
- * @param integer $level
- * @param mixed $spacer
- * @param bool $selected
- * @return
- */
- public function getCatCheckList($parent_id, $level = 0, $spacer, $selected = false)
- {
- if($this->cattree) {
- $class = 'odd';
- if($selected) {
- $arr = explode(",",$selected);
- reset($arr);
- }
- foreach ($this->cattree as $key => $row) {
- if($selected) {
- $sel = (in_array($row['id'], $arr)) ? " checked=\"checked\"" : "";
- $hsel = (in_array($row['id'], $arr)) ? " sel" : "";
- } else {
- $sel = '';
- $hsel = '';
- }
- $class = ($class == 'even' ? 'odd' : 'even');
- if ($parent_id == $row['parent_id']) {
- print "<div class=\"" . $class . $hsel . "\"> <label class=\"checkbox\"><input type=\"checkbox\" name=\"cid[]\" class=\"checkbox\" value=\"" . $row['id'] . "\"".$sel." />";
- for ($i = 0; $i < $level; $i++)
- print $spacer;
- print "<i></i>".$row['name'.Lang::$lang] . "</label></div>\n";
- $level++;
- $this->getCatCheckList($key, $level, $spacer, $selected);
- $level--;
- }
- }
- unset($row);
- }
- }
- /**
- * Digishop::fetchProductCategories()
- *
- * @return
- */
- public function fetchProductCategories()
- {
- if ($result = self::$db->fetch_all("SELECT cid FROM " . self::rTable . " WHERE pid = ".Filter::$id)) {
- $cids = array();
- foreach ($result as $row) {
- $cids[] = $row->cid;
- }
- unset($row);
- $cids = implode(",", $cids);
- } else {
- $cids = "";
- }
- return $cids;
- }
- /**
- * Digishop::getSortCatList()
- *
- * @param integer $parent_id
- * @return
- */
- public function getSortCatList($parent_id = 0)
- {
- $submenu = false;
- $class = ($parent_id == 0) ? "parent" : "child";
- foreach ($this->cattree as $key => $row) {
- if ($row['parent_id'] == $parent_id) {
- if ($submenu === false) {
- $submenu = true;
- print "<ul class=\"sortMenu\">\n";
- }
- print '<li class="dd-item" id="list_' . $row['id'] . '">'
- . '<div class="dd-handle"><a data-id="' . $row['id'] . '" data-name="' . $row['name' . Lang::$lang] . '"'
- . ' data-title="' . Lang::$word->_DELETE . '" data-option="deleteCategory" class="delete">'
- . '<i class="icon red remove sign"></i></a><i class="icon reorder"></i>'
- . '<a href="' . Core::url("modules", "catedit", $row['id']) . '" class="' . $class . '">' . $row['name' . Lang::$lang] . '</a></div>';
- $this->getSortCatList($key);
- print "</li>\n";
- }
- }
- unset($row);
- if ($submenu === true)
- print "</ul>\n";
- }
- /**
- * Digishop::processConfig()
- *
- * @return
- */
- public function processConfig()
- {
- Filter::checkPost('filedir', Lang::$word->_MOD_DS_FILEDIR);
- if (empty(Filter::$msgs)) {
- $data = array('ds_config' => array(
- 'cols' => intval($_POST['cols']),
- 'ipp' => intval($_POST['ipp']),
- 'fpp' => intval($_POST['fpp']),
- 'like' => intval($_POST['like']),
- 'show_counter' => intval($_POST['show_counter']),
- 'filedir' => '"' . base64_encode($_POST['filedir']) . '"',
- 'allow_free' => intval($_POST['allow_free']),
- 'layout' => intval($_POST['layout']),
- 'template' => '"' . base64_encode($_POST['template']) . '"')
- );
- if (INI::write(MODPATH . 'digishop/config.ini', $data)) {
- $json['type'] = 'success';
- $json['message'] = Filter::msgOk(Lang::$word->_MOD_DS_CGFUPDATED, false);
- Security::writeLog(Lang::$word->_MOD_DS_CGFUPDATED, "", "no", "module");
- } else {
- $json['type'] = 'info';
- $json['message'] = Filter::msgAlert(Lang::$word->_PROCCESS_C_ERR . '{admin/modules/digishop/config.ini}', false);
- }
- print json_encode($json);
- } else {
- $json['message'] = Filter::msgStatus();
- print json_encode($json);
- }
- }
- /**
- * Digishop::getProducts()
- *
- * @return
- */
- public function getProducts()
- {
- if (Filter::$id) {
- $where = "WHERE p.cid = " . Filter::$id;
- $counter = countEntries(self::mTable, 'cid', Filter::$id);
- } else {
- $where = null;
- $counter = countEntries(self::mTable);
- }
- if (isset($_POST['fromdate_submit']) && $_POST['fromdate_submit'] <> "" || isset($from) && $from != '') {
- $enddate = date("Y-m-d");
- $fromdate = (empty($from)) ? $_POST['fromdate_submit'] : $from;
- if (isset($_POST['enddate_submit']) && $_POST['enddate_submit'] <> "") {
- $enddate = $_POST['enddate_submit'];
- }
- $where = " WHERE p.created BETWEEN '" . trim($fromdate) . "' AND '" . trim($enddate) . " 23:59:59'";
- $q = "SELECT COUNT(*) FROM " . self::mTable . " WHERE created BETWEEN '" . trim($fromdate) . "' AND '" . trim($enddate) . " 23:59:59' LIMIT 1";
- $record = Registry::get("Database")->query($q);
- $total = Registry::get("Database")->fetchrow($record);
- $counter = $total[0];
- }
- $pager = Paginator::instance();
- $pager->items_total = $counter;
- $pager->default_ipp = Registry::get("Core")->perpage;
- $pager->paginate();
- $sql = "SELECT p.*, c.id as cid, c.name" . Lang::$lang . " as catname,"
- . "\n (SELECT COUNT(pid) FROM " . self::trTable . " WHERE pid = p.id) as sales"
- . "\n FROM " . self::mTable . " as p"
- . "\n LEFT JOIN " . self::ctTable . " as c ON c.id = p.cid"
- . "\n $where"
- . "\n ORDER BY p.created DESC" . $pager->limit;
- $row = self::$db->fetch_all($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::processProduct()
- *
- * @return
- */
- public function processProduct()
- {
- Filter::checkPost('title' . Lang::$lang, Lang::$word->_MOD_DS_NAME);
- Filter::checkPost('cid', Lang::$word->_MOD_DS_CATEGORY);
- Filter::checkPost('price', Lang::$word->_MOD_DS_PRODPRICE);
- if (!Filter::$id) {
- if (empty($_FILES['thumb']['name']))
- Filter::$msgs['thumb'] = Lang::$word->_MOD_DS_PRODIMG;
- if (empty($_FILES['filename']['name']))
- Filter::$msgs['filename'] = Lang::$word->_MOD_DS_PRODFILE;
- if (empty($_FILES['filename2']['name']))
- Filter::$msgs['filename2'] = Lang::$word->_MOD_DS_PRODFILE2;
- }
- if (!empty($_FILES['filename']['name'])) {
- if (!preg_match("/(\.zip|\.rar|\.pdf)$/i", $_FILES['filename']['name']))
- Filter::$msgs['filename'] = Lang::$word->_MOD_DS_PRODFILE_R;
- }
- if (!empty($_FILES['filename2']['name'])) {
- if (!preg_match("/(\.zip|\.rar|\.pdf)$/i", $_FILES['filename2']['name']))
- Filter::$msgs['filename2'] = Lang::$word->_MOD_DS_PRODFILE2_R;
- }
- if (!empty($_FILES['thumb']['name'])) {
- if (!preg_match("/(\.jpg|\.png)$/i", $_FILES['thumb']['name'])) {
- Filter::$msgs['thumb'] = Lang::$word->_CG_LOGO_R;
- }
- $file_info = getimagesize($_FILES['thumb']['tmp_name']);
- if (empty($file_info))
- Filter::$msgs['thumb'] = Lang::$word->_CG_LOGO_R;
- }
- if (empty(Filter::$msgs)) {
- $data = array(
- 'title' . Lang::$lang => sanitize($_POST['title' . Lang::$lang]),
- 'slug' => (empty($_POST['slug'])) ? doSeo($_POST['title' . Lang::$lang]) : doSeo($_POST['slug']),
- 'cid' => intval($_POST['cid'][0]),
- 'price' => floatval($_POST['price']),
- 'token' => md5(time()),
- 'token2' => md5(time()),
- 'active' => intval($_POST['active']),
- 'gallery' => intval($_POST['module_data']),
- 'metakey' . Lang::$lang => sanitize($_POST['metakey' . Lang::$lang]),
- 'metadesc' . Lang::$lang => sanitize($_POST['metadesc' . Lang::$lang]),
- 'body' . Lang::$lang => Filter::in_url($_POST['body' . Lang::$lang]),
- 'active' => 1
- );
- if (empty($_POST['metakey' . Lang::$lang]) or empty($_POST['metadesc' . Lang::$lang])) {
- include (BASEPATH . 'lib/class_meta.php');
- parseMeta::instance($_POST['body' . Lang::$lang]);
- if (empty($_POST['metakey' . Lang::$lang])) {
- $data['metakey' . Lang::$lang] = parseMeta::get_keywords();
- }
- if (empty($_POST['metadesc'])) {
- $data['metadesc' . Lang::$lang] = parseMeta::metaText($_POST['body' . Lang::$lang]);
- }
- }
- if (!Filter::$id) {
- $data['created'] = "NOW()";
- }
- if (isset($_POST['membership_id'])) {
- $data['membership_id'] = Core::_implodeFields($_POST['membership_id']);
- } else
- $data['membership_id'] = 0;
- // Procces Image
- if (!empty($_FILES['thumb']['name'])) {
- $filedir = BASEPATH . self::imagepath;
- $newName = "IMG_" . randName();
- $ext = substr($_FILES['thumb']['name'], strrpos($_FILES['thumb']['name'], '.') + 1);
- $fullname = $filedir . $newName . "." . strtolower($ext);
- if (Filter::$id and $file = getValueById("thumb", self::mTable, Filter::$id)) {
- @unlink($filedir . $file);
- }
- if (!move_uploaded_file($_FILES['thumb']['tmp_name'], $fullname)) {
- die(Filter::msgError(Lang::$word->_FILE_ERR, false));
- }
- $data['thumb'] = $newName . "." . strtolower($ext);
- }
- // Procces File
- if (!empty($_FILES['filename']['name'])) {
- $filedir = $this->filedir;
- $newName = "FILE_" . randName();
- $ext = substr($_FILES['filename']['name'], strrpos($_FILES['filename']['name'], '.') + 1);
- $fullname = $filedir . $newName . "." . strtolower($ext);
- if (Filter::$id and $file = getValueById("filename", self::mTable, Filter::$id)) {
- @unlink($filedir . $file);
- }
- if (!move_uploaded_file($_FILES['filename']['tmp_name'], $fullname)) {
- die(Filter::msgError(Lang::$word->_FILE_ERR, false));
- }
- $data['filename'] = $newName . "." . strtolower($ext);
- $data['filesize'] = filesize($fullname);
- }
- // Procces File2
- if (!empty($_FILES['filename2']['name'])) {
- $filedir = $this->filedir;
- $newName = "FILE_" . randName();
- $ext = substr($_FILES['filename2']['name'], strrpos($_FILES['filename2']['name'], '.') + 1);
- $fullname2 = $filedir . $newName . "." . strtolower($ext);
- if (Filter::$id and $file = getValueById("filename2", self::mTable, Filter::$id)) {
- @unlink($filedir . $file);
- }
- if (!move_uploaded_file($_FILES['filename2']['tmp_name'], $fullname2)) {
- die(Filter::msgError(Lang::$word->_FILE_ERR, false));
- }
- $data['filename2'] = $newName . "." . strtolower($ext);
- $data['filesize2'] = filesize($fullname2);
- }
- (Filter::$id) ? self::$db->update(self::mTable, $data, "id=" . Filter::$id) : $lastid = self::$db->insert(self::mTable, $data);
- if (Filter::$id) {
- // Process Categories
- if (isset($_POST['cid'])) {
- self::$db->delete(self::rTable, "pid = " . Filter::$id);
- foreach ($_POST['cid'] as $cid) {
- $cdata['pid'] = Filter::$id;
- $cdata['cid'] = intval($cid);
- self::$db->insert(self::rTable, $cdata);
- }
- }
- } else {
- // Process Categories
- if (isset($_POST['cid'])) {
- foreach ($_POST['cid'] as $cid) {
- $cdata['pid'] = $lastid;
- $cdata['cid'] = intval($cid);
- self::$db->insert(self::rTable, $cdata);
- }
- }
- }
- $message = (Filter::$id) ? Lang::$word->_MOD_DS_PRODUPDATED : Lang::$word->_MOD_DS_PRODADDED;
- if (self::$db->affected()) {
- Security::writeLog($message, "", "no", "module");
- $json['type'] = 'success';
- $json['message'] = Filter::msgOk($message, false);
- } else {
- $json['type'] = 'success';
- $json['message'] = Filter::msgAlert(Lang::$word->_SYSTEM_PROCCESS, false);
- }
- print json_encode($json);
- } else {
- $json['message'] = Filter::msgStatus();
- print json_encode($json);
- }
- }
- /**
- * Digishop::renderSingleCategory()
- *
- * @return
- */
- private function renderSingleCategory()
- {
- $sql = "SELECT * FROM " . self::ctTable . " WHERE slug = '" . Registry::get("Content")->_url[2] . "' AND active = 1";
- $row = self::$db->first($sql);
- return ($row) ? Registry::get("Content")->moduledata->mod = $row : 0;
- }
- /**
- * Digishop::renderSingleProduct()
- *
- * @return
- */
- public function renderSingleProduct()
- {
- $sql = "SELECT * FROM " . self::mTable . " WHERE slug = '" . Registry::get("Content")->_url[1] . "' AND active = 1";
- $row = self::$db->first($sql);
- return ($row) ? Registry::get("Content")->moduledata->mod = $row : 0;
- }
- /**
- * Digishop::renderProducts()
- *
- * @return
- */
- public function renderProducts()
- {
- $pager = Paginator::instance();
- $pager->items_total = countEntries(self::mTable);
- $pager->default_ipp = $this->fpp;
- $pager->path = doUrl(false, false, "digishop", "?");
- $pager->paginate();
- $sql = "SELECT p.*, c.id as cid, c.name" . Lang::$lang . " as catname, p.title" . Lang::$lang . " as ptitle"
- . "\n FROM " . self::mTable . " as p"
- . "\n LEFT JOIN " . self::ctTable . " as c ON c.id = p.cid"
- . "\n WHERE p.active = 1"
- . "\n AND c.active = 1"
- . "\n ORDER BY p.created DESC" . $pager->limit;
- $row = self::$db->fetch_all($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::renderProductByCategory()
- *
- * @param mixed $cid
- * @return
- */
- public function renderProductByCategory($cid, $slug)
- {
- $q = "SELECT COUNT(p.id) FROM " . self::mTable . " p"
- . "\n INNER JOIN " . self::rTable . " rc on p.id = rc.pid"
- . "\n WHERE rc.cid = " . (int)$cid . " AND p.active = 1 LIMIT 1";
- $record = self::$db->query($q);
- $total = self::$db->fetchrow($record);
- $counter = $total[0];
- $pager = Paginator::instance();
- $pager->items_total = $counter;
- $pager->default_ipp = $this->ipp;
- $pager->path = doUrl(false, $slug, "digishop-cat", "?");
- $pager->paginate();
- $sql = "SELECT p.*, p.title" . Lang::$lang . " as ptitle"
- . "\n FROM " . self::mTable . " as p"
- . "\n INNER JOIN " . self::rTable . " rc ON p.id = rc.pid"
- . "\n LEFT JOIN " . self::ctTable . " as c ON c.id = rc.cid"
- . "\n WHERE rc.cid = " . (int)$cid
- . "\n AND p.active = 1"
- . "\n AND c.active = 1"
- . "\n ORDER BY p.created DESC" . $pager->limit;
- $row = self::$db->fetch_all($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::getLatestPluginDigishop()
- *
- * @return
- */
- public function getLatestPluginDigishop()
- {
- $sql = "SELECT p.*, c.id as cid, c.name" . Lang::$lang . " as catname, p.title" . Lang::$lang . " as ptitle"
- . "\n FROM " . self::mTable . " as p"
- . "\n LEFT JOIN " . self::ctTable . " as c ON c.id = p.cid"
- . "\n WHERE p.active = 1"
- . "\n AND c.active = 1"
- . "\n ORDER BY p.created DESC LIMIT " . $this->fpp;
- $row = self::$db->fetch_all($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::getPriceMembershipData()
- *
- * @param mixed $id
- * @param mixed $token
- * @param mixed $price
- * @param mixed $memid
- * @return
- */
- public function getPriceMembershipData($id, $token, $price, $memid)
- {
- $m_arr = explode(",", $memid);
- reset($m_arr);
- if(Registry::get("Users")->logged_in and Registry::get("Users")->memvalid and in_array(Registry::get("Users")->membership_id, $m_arr)) {
- print '<a href="' . SITEURL . '/modules/digishop/download.php?member=' . $token . '"
- class="wojo warning labeled icon button" data-content="' . Lang::$word->_MOD_DS_MEMVALID . '"><i class="icon download disk"></i>' . Lang::$word->_MOD_DS_DOWNMEM . '</a>';
- } else
- print '<a data-id="' . $id . '" class="wojo warning labeled icon button" data-content="' . Lang::$word->_MOD_DS_MEMREQ . '"><i class="icon user"></i>' . Lang::$word->_MOD_DS_MEMREQ . '</a>';
- }
- public function getPriceMembershipData2($id, $token2, $price, $memid)
- {
- $m_arr = explode(",", $memid);
- reset($m_arr);
- if(Registry::get("Users")->logged_in and Registry::get("Users")->memvalid and in_array(Registry::get("Users")->membership_id, $m_arr)) {
- print '<a href="' . SITEURL . '/modules/digishop/download.php?member=' . $token2 . '"
- class="wojo warning labeled icon button" data-content="' . Lang::$word->_MOD_DS_MEMVALID . '"><i class="icon download disk"></i>' . Lang::$word->_MOD_DS_DOWNMEM . '</a>';
- } else
- print '';
- }
- /**
- * Digishop::getPriceData()
- *
- * @param mixed $id
- * @param mixed $token
- * @param mixed $price
- * @return
- */
- public function getPriceData($id, $token, $price)
- {
- if($price == 0) {
- switch ($this->allow_free) {
- case "1":
- print '<a data-id="' . $id . '" class="add wojo labeled icon button"><i class="icon cart"></i>' . Lang::$word->_MOD_DS_ADD_TO . '</a>';
- print '<a href="' . SITEURL . '/modules/digishop/download.php?free=' . $token . '"
- class="wojo warning button"><i class="icon unlock"></i>' . Lang::$word->_MOD_DS_MSDS . '</a>';
- break;
- case "0" and Registry::get("Digishop")->logged_in :
- print '<a data-id="' . $id . '" class="add wojo labeled icon button"><i class="icon cart"></i>' . Lang::$word->_MOD_DS_ADD_TO . '</a>';
- print '<a href="' . SITEURL . '/modules/digishop/download.php?free=' . $token . '"
- class="wojo warning button"><i class="icon unlock"></i>' . Lang::$word->_MOD_DS_TDS . '</a>';
- break;
- default:
- print Lang::$word->_MOD_DS_LOGIN_TO;
- break;
- }
- } else
- print '';
- }
- public function getPriceData2($id, $token2, $price)
- {
- if($price == 0) {
- switch ($this->allow_free) {
- case "1":
- print '';
- print '<a href="' . SITEURL . '/modules/digishop/download.php?free=' . $token2 . '"
- class="wojo warning button"><i class="icon unlock"></i>' . Lang::$word->_MOD_DS_MSDS . '</a>';
- break;
- case "0" and Registry::get("Digishop")->logged_in :
- print '';
- print '<a href="' . SITEURL . '/modules/digishop/download.php?free=' . $token2 . '"
- class="wojo warning button"><i class="icon unlock"></i>' . Lang::$word->_MOD_DS_TDS . '</a>';
- break;
- default:
- print Lang::$word->_MOD_DS_LOGIN_TO;
- break;
- }
- } else
- print '';
- }
- /**
- * Digishop::layoutSwitchList()
- *
- * @return
- */
- public function layoutSwitchList()
- {
- $active = '';
- if (isset($_COOKIE['DIGIVIEW_CMSPRO']) && $_COOKIE['DIGIVIEW_CMSPRO'] == 'list') {
- $active = ' active';
- } elseif($this->layout == 0 && !isset($_COOKIE['DIGIVIEW_CMSPRO'])) {
- $active = ' active';
- }
- return $active;
- }
- /**
- * Digishop::layoutSwitchGrid()
- *
- * @return
- */
- public function layoutSwitchGrid()
- {
- $active = '';
- if (isset($_COOKIE['DIGIVIEW_CMSPRO']) && $_COOKIE['DIGIVIEW_CMSPRO'] == 'grid') {
- $active = ' active';
- } elseif($this->layout == 1 && !isset($_COOKIE['DIGIVIEW_CMSPRO'])) {
- $active = ' active';
- }
- return $active;
- }
- /**
- * Digishop::getCategories()
- *
- * @return
- */
- public function getCategories($array, $parent_id = 0, $menuid = 'digicats', $class = 'digi-menu')
- {
- if(is_array($array) && count($array) > 0) {
- $submenu = false;
- $attr = (!$parent_id) ? ' class="' . $class . '" id="' . $menuid . '"' : ' class="menu-submenu"';
- $attr2 = (!$parent_id) ? ' class="nav-item"' : ' class="nav-submenu-item"';
- $icon = (!$parent_id) ? '<i class="icon open folder"></i>' :null ;
- foreach ($array as $key => $row) {
- if ($row['parent_id'] == $parent_id) {
- if ($submenu === false) {
- $submenu = true;
- print "<ul" . $attr . ">\n";
- }
- $url = doUrl(false, $row['slug'], "digishop-cat");
- $counter = ($this->show_counter) ? '<small>('.$row['totalitems'].')</small> ' : null;
- $active = (isset(Registry::get("Content")->_url[2]) and Registry::get("Content")->_url[2] == $row['slug']) ? " active" : "normal";
- $link = '<a href="' . $url . '" class="' . $active . '" title="' . $row['name'.Lang::$lang] . '">' . $icon . $row['name'.Lang::$lang] . $counter.'</a>';
- print '<li>';
- print $link;
- $this->getCategories($array, $key);
- print "</li>\n";
- }
- }
- unset($row);
- if ($submenu === true)
- print "</ul>\n";
- }
- }
- /**
- * Digishop::getCatDropList()
- *
- * @return
- */
- public function getCatDropList($parent_id, $level = 0, $spacer, $selected = false)
- {
- foreach ($this->cattree as $key => $row) {
- $sel = ($row['id'] == $selected) ? " selected=\"selected\"" : "" ;
- if ($parent_id == $row['parent_id']) {
- print "<option value=\"" . $row['id'] . "\"".$sel.">";
- for ($i = 0; $i < $level; $i++)
- print $spacer;
- print $row['name'.Lang::$lang] . "</option>\n";
- $level++;
- $this->getCatDropList($key, $level, $spacer, $selected);
- $level--;
- }
- }
- unset($row);
- }
- /**
- * Digishop::processCategory()
- *
- * @return
- */
- public function processCategory()
- {
- Filter::checkPost('name' . Lang::$lang, Lang::$word->_MOD_DS_CATNAME);
- if (empty(Filter::$msgs)) {
- $data = array(
- 'name' . Lang::$lang => sanitize($_POST['name' . Lang::$lang]),
- 'parent_id' => intval($_POST['parent_id']),
- 'slug' => (empty($_POST['slug'])) ? doSeo($_POST['name' . Lang::$lang]) : doSeo($_POST['slug']),
- 'metakey' . Lang::$lang => sanitize($_POST['metakey' . Lang::$lang]),
- 'metadesc' . Lang::$lang => sanitize($_POST['metadesc' . Lang::$lang]),
- 'active' => 1
- );
- (Filter::$id) ? self::$db->update(self::ctTable, $data, "id=" . Filter::$id) : self::$db->insert(self::ctTable, $data);
- $message = (Filter::$id) ? Lang::$word->_MOD_DS_CATUPDATED : Lang::$word->_MOD_DS_CATADDED;
- if (self::$db->affected()) {
- Security::writeLog($message, "", "no", "module");
- $json['type'] = 'success';
- $json['message'] = Filter::msgOk($message, false);
- } else {
- $json['type'] = 'success';
- $json['message'] = Filter::msgAlert(Lang::$word->_SYSTEM_PROCCESS, false);
- }
- print json_encode($json);
- } else {
- $json['message'] = Filter::msgStatus();
- print json_encode($json);
- }
- }
- /**
- * Digishop::getCategoryList()
- *
- * @return
- */
- public function getCategoryList($active = false)
- {
- $where = ($active) ? "WHERE active = 1" : null;
- $sql = "SELECT *, "
- . "\n (SELECT COUNT(" . self::mTable . ".cid) FROM " . self::mTable . " WHERE " . self::mTable . ".cid = " . self::ctTable . ".id) as total"
- . "\n FROM " . self::ctTable
- . "\n $where"
- . "\n ORDER BY sorting";
- $row = self::$db->fetch_all($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::getPayments()
- *
- * @param bool $from
- * @return
- */
- public function getPayments($from = false)
- {
- if (isset($_POST['fromdate_submit']) && $_POST['fromdate_submit'] <> "" || isset($from) && $from != '') {
- $enddate = date("Y-m-d");
- $fromdate = (empty($from)) ? $_POST['fromdate_submit'] : $from;
- if (isset($_POST['enddate_submit']) && $_POST['enddate_submit'] <> "") {
- $enddate = $_POST['enddate_submit'];
- }
- $q = "SELECT COUNT(*) FROM " . self::trTable . " WHERE created BETWEEN '" . trim($fromdate) . "' AND '" . trim($enddate) . " 23:59:59'";
- $where = " WHERE t.created BETWEEN '" . trim($fromdate) . "' AND '" . trim($enddate) . " 23:59:59'";
- } else {
- $q = "SELECT COUNT(*) FROM " . self::trTable . " LIMIT 1";
- $where = null;
- }
- $record = self::$db->query($q);
- $total = self::$db->fetchrow($record);
- $counter = $total[0];
- $pager = Paginator::instance();
- $pager->items_total = $counter;
- $pager->default_ipp = Registry::get("Core")->perpage;
- $pager->paginate();
- $sql = "SELECT t.*, t.id as id, u.id as uid, u.username, p.id as did, p.title" . Lang::$lang
- . "\n FROM " . self::trTable . " as t"
- . "\n LEFT JOIN " . Users::uTable . " as u ON u.id = t.uid"
- . "\n LEFT JOIN " . self::mTable . " as p ON p.id = t.pid"
- . "\n " . $where
- . "\n ORDER BY t.created DESC" . $pager->limit;
- $row = self::$db->fetch_all($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::activateTransaction()
- *
- * @return
- */
- public function activateTransaction()
- {
- $row = self::$db->first("SELECT t.*, t.id as id, p.title" . Lang::$lang . " as atitle, u.email, CONCAT(u.fname,' ',u.lname) as name"
- . "\n FROM " . self::trTable . " as t"
- . "\n LEFT JOIN " . Users::uTable . " as u ON u.id = t.uid"
- . "\n LEFT JOIN " . self::mTable . " as p ON p.id = t.pid"
- . "\n WHERE t.id = " . Filter::$id);
- if ($row) {
- require_once (BASEPATH . "lib/class_mailer.php");
- $mailer = Mailer::sendMail();
- $items = '
- <table width="100%" border="0" cellpadding="4" cellspacing="2">
- <thead>
- <tr>
- <td width="20"><strong>#</strong></td>
- <td><strong>' . Lang::$word->_MOD_DS_NAME . '</strong></td>
- <td><strong>' . Lang::$word->_MOD_DS_PRODPRICE . '</strong></td>
- <td><strong>' . Lang::$word->_MOD_DS_QTY . '</strong></td>
- <td><strong>' . Lang::$word->_MOD_DS_TOTPRICE . '</strong></td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . $row->id . '.</td>
- <td style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . sanitize($row->atitle, 30) . '</td>
- <td style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . Registry::get("Core")->formatMoney($row->price) . '</td>
- <td align="center" style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . $row->item_qty . '</td>
- <td align="right" style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . Registry::get("Core")->formatMoney($row->item_qty * $row->price) . '</td>
- </tr>
- <tr>
- <td colspan="4" align="right" valign="top"><strong style="color:#F00">' . Lang::$word->_MOD_DS_GTOTAL . ':</strong></td>
- <td align="right" valign="top"><strong style="color:#F00">' . Registry::get("Core")->formatMoney($row->item_qty * $row->price) . '</strong></td>
- </tr>
- </tbody>
- </table>';
- $body = str_replace(array(
- '[NAME]',
- '[ITEMS]',
- '[DASH]',
- '[SITE_NAME]',
- '[URL]'), array(
- $row->name,
- $items,
- doUrl(false, Registry::get("Core")->account_page, "page"),
- Registry::get("Core")->site_name,
- SITEURL), $this->template);
- $message = Swift_Message::newInstance()
- ->setSubject(Lang::$word->_MOD_DS_R_SUBJECT . Registry::get("Core")->site_name)
- ->setTo(array($row->email => $row->name))
- ->setFrom(array(Registry::get("Core")->site_email => Registry::get("Core")->site_name))
- ->setBody(cleanOut($body), 'text/html');
- if ($mailer->send($message)):
- $data = array(
- 'status' => 1,
- 'active' => 1,
- );
- self::$db->update(self::trTable, $data, "id = " . Filter::$id);
- $json['type'] = 'success';
- $json['title'] = Lang::$word->_SUCCESS;
- $json['message'] = Lang::$word->_MOD_DS_RSENT;
- else:
- $json['type'] = 'error';
- $json['title'] = Lang::$word->_ERROR;
- $json['message'] = Lang::$word->_MOD_DS_RSENT_ERR;
- endif;
- print json_encode($json);
- }
- }
- /**
- * Digishop::getUserTransactions()
- *
- * @param bool $sesid
- * @return
- */
- public function getUserTransactions()
- {
- $sql = "SELECT t.*, p.id as pid, p.title" . Lang::$lang . " as ptitle, p.price, p.thumb, p.slug"
- . "\n FROM " . self::trTable . " as t"
- . "\n LEFT JOIN " . self::mTable . " as p ON p.id = t.pid"
- . "\n WHERE t.uid = " . Registry::get("Users")->uid
- . "\n AND t.status = 1"
- . "\n AND t.active = 1"
- . "\n AND p.active = 1"
- . "\n GROUP BY t.pid ORDER BY t.created DESC";
- $row = self::$db->fetch_all($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::getCartContent()
- *
- * @param bool $sesid
- * @return
- */
- public function getCartContent($sesid = false)
- {
- $uid = ($sesid) ? $sesid : Registry::get("Users")->sesid;
- $sql = "SELECT c.*, p.id as pid, p.title" . Lang::$lang . " as ptitle, p.price, p.thumb, p.slug, COUNT(c.pid) as total"
- . "\n FROM " . self::xTable . " as c"
- . "\n LEFT JOIN " . self::mTable . " as p ON p.id = c.pid"
- . "\n WHERE c.user_id = '" . self::$db->escape($uid) . "'"
- . "\n GROUP BY c.pid ORDER BY c.pid DESC";
- $row = self::$db->fetch_all($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::getCartTotal()
- *
- * @param bool $sesid
- * @return
- */
- public function getCartTotal($sesid = false)
- {
- $uid = ($sesid) ? $sesid : Registry::get("Users")->sesid;
- $sql = "SELECT SUM(c.price) as total, COUNT(c.pid) as titems"
- . "\n FROM " . self::xTable . " as c"
- . "\n WHERE c.user_id = '" . self::$db->escape($uid) . "'"
- . "\n GROUP BY c.user_id";
- $row = self::$db->first($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::getFreeDownload()
- *
- * @param mixed $token
- * @return
- */
- public function getFreeDownload($token)
- {
- $id = sanitize($token);
- $id = self::$db->escape($token);
- $sql = "SELECT * FROM " . self::mTable
- . "\n WHERE token = '" .$id . "' AND active = 1 AND price = 0";
- $row = self::$db->first($sql);
- return ($row) ? $row : 0;
- }
- public function getFreeDownload2($token2)
- {
- $id = sanitize($token2);
- $id = self::$db->escape($token2);
- $sql = "SELECT * FROM " . self::mTable
- . "\n WHERE token2 = '" .$id . "' AND active = 1 AND price = 0";
- $row = self::$db->first($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::getMembershipDownload()
- *
- * @param mixed $token
- * @return
- */
- public function getMembershipDownload($token)
- {
- $id = sanitize($token);
- $id = self::$db->escape($token);
- $sql = "SELECT * FROM " . self::mTable
- . "\n WHERE token = '" .$id . "' AND active = 1 AND membership_id <> 0";
- $row = self::$db->first($sql);
- return ($row) ? $row : 0;
- }
- public function getMembershipDownload2($token2)
- {
- $id = sanitize($token2);
- $id = self::$db->escape($token2);
- $sql = "SELECT * FROM " . self::mTable
- . "\n WHERE token2 = '" .$id . "' AND active = 1 AND membership_id <> 0";
- $row = self::$db->first($sql);
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::getPaidDownload()
- *
- * @param mixed $token
- * @return
- */
- public function getPaidDownload($token)
- {
- $id = sanitize($token);
- $id = self::$db->escape($token);
- $row = self::$db->first("SELECT t.*, p.filename"
- . " \n FROM " . self::trTable . " as t"
- . " \n LEFT JOIN " . self::mTable . " as p ON t.pid = p.id"
- . " \n WHERE t.token = '" . self::$db->escape($id) . "'"
- . " \n AND t.uid = " . Registry::get("Users")->uid
- . " \n AND t.status = 1 AND t.active = 1"
- . " \n AND p.active = 1");
- return ($row) ? $row : 0;
- }
- public function getPaidDownload2($token2)
- {
- $id = sanitize($token2);
- $id = self::$db->escape($token2);
- $row = self::$db->first("SELECT t.*, p.filename2"
- . " \n FROM " . self::trTable . " as t"
- . " \n LEFT JOIN " . self::mTable . " as p ON t.pid = p.id"
- . " \n WHERE t.token2 = '" . self::$db->escape($id) . "'"
- . " \n AND t.uid = " . Registry::get("Users")->uid
- . " \n AND t.status = 1 AND t.active = 1"
- . " \n AND p.active = 1");
- return ($row) ? $row : 0;
- }
- /**
- * Digishop::verifyTxnId()
- *
- * @param mixed $txn_id
- * @return
- */
- public static function verifyTxnId($txn_id)
- {
- $sql = self::$db->query("SELECT id"
- . "\n FROM ".self::trTable.""
- . "\n WHERE txn_id = '" . sanitize($txn_id) . "'"
- . "\n LIMIT 1");
- if (self::$db->numrows($sql) > 0)
- return false;
- else
- return true;
- }
- /**
- * Digishop::downloadErrors()
- *
- * @return
- */
- public static function downloadErrors()
- {
- print '<div id="showerror" style="display:none"> ';
- switch($_GET['msg']) {
- case 1 :
- print '<p class="wojo warning message"><i class="icon attention"></i> ' . Lang::$word->_MOD_DS_MSG1 . '</p>';
- break;
- case 2 :
- print '<p class="wojo warning message"><i class="icon attention"></i> ' . Lang::$word->_MOD_DS_MSG2 . '</p>';
- break;
- case 3 :
- print '<p class="wojo warning message"><i class="icon attention"></i> ' . Lang::$word->_MOD_DS_MSG3 . '</p>';
- break;
- case 4 :
- print '<p class="wojo warning message"><i class="icon attention"></i> ' . Lang::$word->_MOD_DS_MSG4 . '</p>';
- break;
- case 5 :
- print '<p class="wojo error message"><i class="icon attention"></i>' . str_replace("[IP]", $_SERVER['REMOTE_ADDR'], Lang::$word->_MOD_DS_MSG5) . '</p>';
- break;
- }
- print '</div>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment