Example #1
0
 public function getEvents($full, $start_date, $end_date = null)
 {
     $events = array();
     if ($full) {
         $select = '*';
     } else {
         $select = 'DAYOFMONTH(start_time) AS dom, event_name, MONTH(start_time) AS month, id';
     }
     $sql = 'SELECT ' . $select . ' FROM ' . Model::getTable('Event') . ' WHERE start_time > \'' . $start_date->getMySQLTime() . '\'';
     if ($end_date !== null) {
         $sql .= ' AND start_time < \'' . $end_date->getMySQLTime() . '\'';
     }
     $sql .= ' AND status != ' . Status::DELETED;
     $sql .= ' ORDER BY start_time';
     $error = 'Could not get events.';
     $result = $this->query($sql, $error);
     if ($full) {
         foreach ($result as $row) {
             array_push($events, $row);
         }
     } else {
         foreach ($result as $row) {
             $index = sprintf("%02d", $row['month']) . sprintf("%02d", $row['dom']);
             if (!isset($events[$index])) {
                 $events[$index] = array();
             }
             array_push($events[$index], $row);
             //	$row
         }
     }
     return $events;
 }
 public function rename()
 {
     $this->setTemplate('elib://admin/properties.tpl');
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
         if (isset($_POST['save'])) {
             $p = Model::load('Property');
             $p->id = $_GET['id'];
             $p->load();
             $p->name = $_POST['name'];
             $p->validates();
             if ($p->hasValErrors()) {
                 $this->presenter->assign('property', $p);
                 $this->presenter->assign('errors', $p->getValErrors());
             } else {
                 $p->save(Model::getTable('Property'), array(), 1);
                 $this->redirect('admin/properties');
             }
         } else {
             $p = Model::load('Property');
             $p->id = $_GET['id'];
             $p->load();
             $this->presenter->assign('property', $p);
         }
     }
 }
Example #3
0
 public function getAllWithOptionsForProduct($props, $opts)
 {
     if (sizeof($props) > 0) {
         $props_string = '(' . implode(',', $props) . ')';
     }
     $property = array();
     $sql = 'SELECT t1.id, t1.name, t2.id AS option_id, t2.option_val FROM ' . Model::getTable('Property') . ' t1 ' . 'LEFT JOIN ' . Model::getTable('PropertyOption') . ' t2 ON t2.property_id = t1.id';
     if (isset($props_string)) {
         $sql .= ' WHERE t1.id IN' . $props_string;
     }
     if ($opts != '(0,)') {
         $sql .= ' AND t2.id IN' . $opts;
     }
     $sql .= ' ORDER BY t1.name, t2.option_val';
     $error = 'Could not get all properties and options.';
     $result = $this->query($sql, $error);
     if ($result->rowCount() > 0) {
         foreach ($result as $row) {
             $id = $row['id'];
             if (!isset($property[$id]['name'])) {
                 $property[$id]['name'] = $row['name'];
             }
             if (isset($row['option_id'])) {
                 $option_id = $row['option_id'];
                 $property[$id]['option'][$option_id] = $row['option_val'];
             }
         }
     }
     return $property;
 }
Example #4
0
 public function __construct($items, $c)
 {
     $s = Model::load('ShippingAddress');
     $s->id = \Empathy\Session::get('shipping_address_id');
     $s->load();
     $o = Model::load('OrderItem');
     $o->user_id = CurrentUser::getUserID();
     $o->status = 'DEFAULT';
     $o->stamp = 'MYSQLTIME';
     $o->first_name = $s->first_name;
     $o->last_name = $s->last_name;
     $o->address1 = $s->address1;
     $o->address2 = $s->address2;
     $o->city = $s->city;
     $o->state = $s->state;
     $o->zip = $s->zip;
     $o->country = $s->country;
     $this->invoice_no = $o->insert(Model::getTable('OrderItem'), 1, array(), 0);
     if (!defined('ELIB_PAYPAL_TEST_MODE') || defined('ELIB_PAYPAL_TEST_MODE') && !ELIB_PAYPAL_TEST_MODE) {
         $this->invoice_no = time() . '/' . $this->invoice_no;
     }
     $l = Model::load('LineItem');
     foreach ($items as $item) {
         if (is_numeric($item['qty']) && $item['qty'] > 0) {
             $l->order_id = $this->invoice_no;
             $l->variant_id = $item['id'];
             $l->price = $item['price'];
             $l->quantity = $item['qty'];
             $l->insert(Model::getTable('LineItem'), 1, array(), 0);
         }
     }
 }
Example #5
0
 public function password()
 {
     $this->setTemplate('elib:/admin/password.tpl');
     if (isset($_POST['submit'])) {
         $errors = array();
         $old_password = md5(SALT . $_POST['old_password'] . SALT);
         $password1 = $_POST['password1'];
         $password2 = $_POST['password2'];
         $u = Model::load('UserItem');
         $u->id = Session::get('user_id');
         $u->load();
         if ($old_password != $u->password) {
             array_push($errors, 'The existing password you have entered is not correct');
         }
         if ($password1 != $password2) {
             array_push($errors, 'The new password entered does not match the confirmation');
         }
         if (!ctype_alnum($password1) || !ctype_alnum($password2)) {
             array_push($errors, 'Please only use alpha and numeric characters for new passwords');
         }
         if (sizeof($errors) < 1) {
             $u->password = md5(SALT . $password1 . SALT);
             $u->save(Model::getTable('UserItem'), array(), 0);
             $this->redirect('admin');
         } else {
             $this->presenter->assign('error', $errors);
         }
     } elseif (isset($_POST['cancel'])) {
         $this->redirect('admin');
     }
 }
Example #6
0
 public function getBlogs($tags)
 {
     $id = array();
     $sql = 'SELECT DISTINCT b.id FROM ' . Model::getTable('BlogItem') . ' b';
     $i = 0;
     foreach ($tags as $tag) {
         $glue = 't' . ($i + 1);
         $sql .= ' LEFT JOIN ' . Model::getTable('BlogTag') . ' ' . $glue . ' ON ' . $glue . '.tag_id = ' . $tag;
         $i++;
     }
     $i = 0;
     foreach ($tags as $tag) {
         $glue = 't' . ($i + 1);
         if ($i == 0) {
             $sql .= ' WHERE';
         } else {
             $sql .= ' AND';
         }
         $sql .= ' b.id = ' . $glue . '.blog_id';
         $i++;
     }
     $error = 'Could not get active blog ids.';
     $result = $this->query($sql, $error);
     $i = 0;
     foreach ($result as $row) {
         $id[$i] = $row['id'];
         $i++;
     }
     return $id;
 }
 public function loadFromCart($c)
 {
     $ids = array();
     $product_data = array();
     if (($cart = Session::get('cart')) != false) {
         foreach ($cart as $v => $qty) {
             array_push($ids, $v);
         }
         $v = Model::load('ProductVariant');
         $id_string = $v->buildUnionString($ids);
         $product_data = $v->getCartData($id_string);
         foreach ($product_data as $index => $value) {
             $id = $value['id'];
             $price = $value['price'];
             $qty = $cart[$id]['qty'];
             $product_data[$index]['qty'] = $qty;
             $product_data[$index]['line'] = $qty * $price;
             $product_data[$index]['stamp'] = $cart[$id]['stamp'];
         }
         // sort
         foreach ($product_data as $key => $row) {
             $stamp[$key] = $row['stamp'];
             unset($row['stamp']);
         }
         array_multisort($stamp, SORT_ASC, $product_data);
     }
     return $product_data;
 }
 public function default_event()
 {
     if (isset($_POST['verify'])) {
         $v = Model::load('Vendor');
         $v->id = $_POST['vendor_id'];
         $v->load();
         $u = Model::load('UserItem');
         $u->id = $v->user_id;
         $u->load();
         if ($u->active && $v->name != '') {
             $u->auth = Access::VENDOR;
             $u->save(Model::getTable('UserItem'), array(), 2);
             $v->verified = 'MYSQLTIME';
             $v->save(Model::getTable('Vendor'), array(), 2);
             $p = Model::load('ProductItem');
             $p->verify($v->id);
         }
         $this->redirect('admin/vendors');
     } else {
         $v = Model::load('Vendor');
         $select = '*,UNIX_TIMESTAMP(registered) AS registered, t2.id as vendor_id';
         $t1 = Model::getTable('UserItem');
         $t2 = Model::getTable('Vendor');
         $t3 = Model::getTable('ShippingAddress');
         $sql = ' WHERE t1.id = t2.user_id AND t1.id = t3.user_id AND t3.default_address = 1';
         $page = 1;
         $per_page = 10;
         $vendors = $v->getAllCustomPaginateMultiJoin($select, $t1, $t2, $t3, $sql, $page, $per_page);
         $paginate = $v->getPaginatePagesMultiJoin($select, $t1, $t2, $t3, $sql, $page, $per_page);
         $this->assign('vendors', $vendors);
         $this->assign('paginate', $paginate);
         $this->setTemplate('elib://admin/vendors.tpl');
     }
 }
 public function default_event()
 {
     $o = Model::load('OrderItem');
     $orders = $o->getOrders();
     $this->presenter->assign('orders', $orders);
     $this->setTemplate('elib://admin/orders.tpl');
 }
Example #10
0
 public static function assertAdmin($c)
 {
     $ua = Model::load('UserAccess', null, false);
     if (self::$u->id < 1 || self::$u->getAuth(self::$u->id) < $ua->getLevel('admin')) {
         Session::down();
         $c->redirect("user/login");
     }
 }
Example #11
0
 public function __construct($boot)
 {
     parent::__construct($boot);
     $this->section = Model::load('SectionItem');
     $this->data_item = Model::load('DataItem');
     $this->section->id = $_GET['section'];
     $this->section->load();
     $this->assign('template', $this->section->template);
 }
Example #12
0
 private function getCommentsFetch($id)
 {
     $bc = Model::load('BlogComment');
     $sql = ' WHERE t1.user_id = t2.id';
     $sql .= ' AND t1.status = 1';
     $sql .= ' AND t1.blog_id = ' . $id;
     $sql .= ' ORDER BY t1.stamp';
     return $bc->getAllCustomPaginateSimpleJoin('*,t1.id AS id', Model::getTable('BlogComment'), Model::getTable('UserItem'), $sql, 1, 200);
 }
 public function default_event()
 {
     $this->setTemplate('events.tpl');
     $now = new DateTime(array(time() - 43200));
     // minus 12 hours
     $e = Model::load('Event');
     $events = $e->getEvents(true, $now);
     $this->assign('events', $events);
 }
 public function add()
 {
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
         $p = Model::load('PromoItem');
         $p->category_id = $_GET['id'];
         $p->name = 'New Promo';
         $p->hidden = 'DEFAULT';
         $id = $p->insert(Model::getTable('PromoItem'), 1, array(), 0);
     }
     $this->redirect('admin/promo_category/' . $_GET['id']);
 }
Example #15
0
 public function update($id, $new_sizes)
 {
     $sql = 'DELETE FROM ' . Model::getTable('ContainerImageSize') . ' WHERE container_id = ' . $id;
     $error = 'Could not clear old image sizes from container.';
     $this->query($sql, $error);
     foreach ($new_sizes as $index => $size_id) {
         $sql = 'INSERT INTO ' . Model::getTable('ContainerImageSize') . ' VALUES(' . $id . ', ' . $size_id . ')';
         $error = 'Could not inert new image size';
         $this->query($sql, $error);
     }
 }
Example #16
0
 public function hasCats($id)
 {
     $cats = 0;
     $sql = 'SELECT id FROM ' . Model::getTable('BlogCategory') . ' WHERE blog_category_id = ' . $id;
     $error = 'Could not check for existing child categories.';
     $result = $this->query($sql, $error);
     if ($result->rowCount() > 0) {
         $cats = 1;
     }
     return $cats;
 }
Example #17
0
 public function getBios()
 {
     $sql = 'SELECT t1.id AS artist_id, t3.id AS product_id, t1.artist_alias,' . ' t1.forename, t1.surname, t1.bio, t3.name, t3.image, t3.category_id, t3.price' . ' FROM ' . Model::getTable('ArtistItem') . ' t1' . ' LEFT JOIN ' . Model::getTable('ProductArtist') . ' t2 ON t2.artist_id = t1.id' . ' LEFT JOIN ' . Model::getTable('ProductItem') . ' t3 ON t3.id = t2.product_id' . ' ORDER BY t1.id';
     $error = 'Could not get bios.';
     $result = $this->query($sql, $error);
     $last_artist_id = 0;
     $bio = array();
     $bios = array();
     $book = array();
     $books = array();
     if ($result->rowCount() > 0) {
         foreach ($result as $row) {
             if ($last_artist_id != $row['artist_id']) {
                 if (sizeof($books) > 0) {
                     $bio['books'] = $books;
                     $books = array();
                 }
                 if (sizeof($bio) > 0) {
                     array_push($bios, $bio);
                     $bio = array();
                 }
                 $last_artist_id = $row['artist_id'];
                 $bio['artist_id'] = $row['artist_id'];
                 $bio['artist_alias'] = $row['artist_alias'];
                 $bio['forename'] = $row['forename'];
                 $bio['surname'] = $row['surname'];
                 if ($row['artist_alias'] == '') {
                     $bio['artist'] = $row['forename'] . ' ' . $row['surname'];
                 } else {
                     $bio['artist'] = $row['artist_alias'];
                 }
                 $bio['bio'] = $row['bio'];
             }
             if (isset($row['product_id'])) {
                 if ($row['category_id'] == 14) {
                     $book = array();
                     $book['id'] = $row['product_id'];
                     $book['image'] = $row['image'];
                     $book['name'] = $row['name'];
                     $book['price'] = $row['price'];
                     array_push($books, $book);
                 }
             }
         }
     }
     if (sizeof($books) > 0) {
         $bio['books'] = $books;
     }
     if (sizeof($bio) > 0) {
         array_push($bios, $bio);
     }
     return $bios;
 }
 public function getActiveOptions($product_id)
 {
     $ids = array();
     $sql = 'SELECT DISTINCT property_option_id AS id' . ' FROM ' . Model::getTable('ProductVariantPropertyOption') . ' t1,' . ' ' . Model::getTable('ProductVariant') . ' t2' . ' WHERE t2.id = t1.product_variant_id' . ' AND t2.product_id = ' . $product_id . ' AND t2.status = ' . ProductVariantStatus::AVAILABLE;
     $error = 'Could not get active option ids for product.';
     $result = $this->query($sql, $error);
     if ($result->rowCount() > 0) {
         foreach ($result as $row) {
             array_push($ids, $row['id']);
         }
     }
     return $ids;
 }
 public function getContainerPrefixes($container_id)
 {
     $prefix = array();
     $sql = 'SELECT prefix FROM ' . Model::getTable('ImageSize') . ' i, ' . Model::getTable('ContainerImageSize') . ' c WHERE c.image_size_id = i.id' . ' AND c.container_id = ' . $container_id;
     $error = 'Could not get image sizes for container.';
     $result = $this->query($sql, $error);
     if ($result->rowCount() > 0) {
         foreach ($result as $row) {
             array_push($prefix, $row['prefix'] . '_');
         }
     }
     return $prefix;
 }
 public function update_timestamps()
 {
     // current section
     $this->section->load();
     $this->section->stamp = date('Y-m-d H:i:s', time());
     $this->section->save(Model::getTable('SectionItem'), array(), 2);
     // ancestors => make optional?
     $ancestors = array();
     $ancestors = $this->section->getAncestorIDs($this->section->id, $ancestors);
     if (sizeof($ancestors) > 0) {
         $update = $this->section->buildUnionString($ancestors);
         $this->section->updateTimestamps($update);
     }
 }
 public function getPropertiesByCategory($cat)
 {
     $categories = '(' . implode(',', $cat) . ')';
     $properties = array();
     $sql = 'SELECT property_id FROM ' . Model::getTable('CategoryProperty') . ' WHERE category_id IN' . $categories;
     $error = "Could not find cactive category properties.";
     $result = $this->query($sql, $error);
     $i = 0;
     foreach ($result as $row) {
         $properties[$i] = $row['property_id'];
         $i++;
     }
     return $properties;
 }
 public function getColoursIndexed($property_id)
 {
     $colour = array();
     $sql = 'SELECT * FROM ' . Model::getTable('PropertyOption') . ' WHERE property_id = ' . $property_id . ' ORDER BY option_val';
     $error = 'Could not get colours.';
     $result = $this->query($sql, $error);
     if ($result->rowCount() > 0) {
         foreach ($result as $row) {
             $id = $row['id'];
             $colour[$id] = $row['option_val'];
         }
     }
     return $colour;
 }
Example #23
0
 public function getBrands()
 {
     $brand = array();
     $brand[0] = 'None';
     $sql = 'SELECT * FROM ' . Model::getTable('BrandItem') . ' ORDER BY name';
     $error = 'Could not get list of brands.';
     $result = $this->query($sql, $error);
     if ($result->rowCount() > 0) {
         foreach ($result as $row) {
             $id = $row['id'];
             $brand[$id] = $row['name'];
         }
     }
     return $brand;
 }
Example #24
0
 public function getForIDs($ids)
 {
     $images = array();
     $i = 0;
     foreach ($ids as $item) {
         $sql = 'SELECT * FROM ' . Model::getTable('BlogImage') . ' WHERE blog_id = ' . $item . ' ORDER BY id';
         $error = 'Could not get blog images.';
         $result = $this->query($sql, $error);
         if ($result->rowCount() > 0) {
             foreach ($result as $row) {
                 $images[$item][$i] = $row;
                 $i++;
             }
         }
     }
     return $images;
 }
 public function setDefault($user_id, $address_id)
 {
     $sql = 'SELECT id FROM ' . Model::getTable('ShippingAddress') . ' WHERE user_id = ' . $user_id;
     $error = 'Could not get all shipping addresses for user.';
     $result = $this->query($sql, $error);
     $addresses = array();
     foreach ($result as $row) {
         array_push($addresses, $row['id']);
     }
     if (in_array($address_id, $addresses)) {
         $sql = 'UPDATE ' . Model::getTable('ShippingAddress') . ' SET default_address = 0 WHERE user_id = ' . $user_id;
         $error = 'Could not wipe defaults.';
         $this->query($sql, $error);
         $sql = 'UPDATE ' . Model::getTable('ShippingAddress') . ' SET default_address = 1 WHERE id = ' . $address_id;
         $error = 'Could not set new default';
         $this->query($sql, $error);
     }
 }
Example #26
0
 public function getDataFiles()
 {
     $images = array();
     $ids = array();
     $sql = 'SELECT id from ' . Model::getTable('DataItem') . ' d,' . Model::getTable('ContainerImageSize') . ' c WHERE c.image_size_id = ' . $this->id . ' AND c.container_id = d.container_id';
     $error = 'Could not get data item containers that are using selected image size.';
     $result = $this->query($sql, $error);
     foreach ($result as $row) {
         $ids[] = $row['id'];
     }
     if (sizeof($ids) > 0) {
         $sql = 'SELECT image FROM ' . Model::getTable('DataItem') . ' WHERE data_item_id IN' . $this->buildUnionString($ids);
         $error = 'Could not got images matching image size.';
         $result = $this->query($sql, $error);
         foreach ($result as $row) {
             $images[] = $row['image'];
         }
     }
     return $images;
 }
Example #27
0
 public static function addToIndex($b)
 {
     if (defined('ELIB_BLOG_ELASTIC') && ELIB_BLOG_ELASTIC) {
         $bt = Model::load('BlogTag');
         $bc = Model::load('BlogCategory');
         $cats = $bc->getCategoriesForBlogItem($b->id);
         $cats_arr = array();
         foreach ($cats as $c) {
             $item = Model::load('BlogCategory');
             $item->id = $c;
             $item->load();
             array_push($cats_arr, $item->label);
         }
         $params = ['index' => 'elib_blog', 'type' => 'blog', 'id' => $b->id, 'body' => ['heading' => $b->heading, 'stamp' => $b->stamp, 'tags' => $bt->getTags($b->id), 'body' => strip_tags($b->body), 'slug' => $b->slug, 'categories' => $cats_arr]];
         //header('Content-type: application/json');
         //echo json_encode($params); exit();
         $client = ClientBuilder::create()->build();
         $response = $client->index($params);
     }
 }
Example #28
0
 public function getOrders()
 {
     $order = array();
     $sql = 'SELECT t3.id AS order_id, username, t2.status, stamp, SUM(t4.price) AS total' . ' FROM ' . Model::getTable('UserItem') . ' t1, ' . Model::getTable('OrderStatus') . ' t2, ' . Model::getTable('OrderItem') . ' t3' . ' LEFT JOIN ' . Model::getTable('LineItem') . ' t4 ON t4.order_id = t3.id' . ' WHERE t1.id = t3.user_id AND t2.id = t3.status' . ' GROUP BY t3.id' . ' ORDER BY stamp DESC';
     $error = 'Could not get orders.';
     $result = $this->query($sql, $error);
     if ($result->rowCount() > 0) {
         foreach ($result as $row) {
             $item = array();
             $item['id'] = $row['order_id'];
             $item['username'] = $row['username'];
             $item['stamp'] = $row['stamp'];
             $item['status'] = $row['status'];
             if ($row['total'] == '') {
                 $row['total'] = 0;
             }
             $item['total'] = $row['total'];
             array_push($order, $item);
         }
     }
     return $order;
 }
Example #29
0
 public function confirm_reg()
 {
     $reg_code = $_GET['code'];
     $u = Model::load('UserItem');
     $id = $u->findUserForActivation($reg_code);
     if ($id > 0) {
         $u->id = $id;
         $u->load();
         $password = $u->password;
         $u->password = md5(SALT . $password . SALT);
         $u->active = 1;
         $u->activated = 'MYSQLTIME';
         $u->save(Model::getTable('UserItem'), array(), 0);
         Session::set('user_id', $u->id);
         $message = "\nHi ___,\n\n" . "Thanks for confirming your registration. You can now log in to the " . ELIB_EMAIL_ORGANISATION . " website using your username " . " '___' and the password '" . $password . "'.\n\nCheers\n\n";
         $r[0]['alias'] = $u->username;
         $r[0]['address'] = $u->email;
         $m = new Mailer($r, 'Welcome to ' . ELIB_EMAIL_ORGANISATION, $message, ELIB_EMAIL_FROM);
         $this->redirect('user/thanks/2');
     } else {
         throw new \Exception('Unable to activate user.');
     }
 }
Example #30
0
 public function monthView()
 {
     $month = $this->filterInt('month');
     if (strlen($month) != 6) {
         $month = 0;
     }
     if ($month == 0) {
         $time = time();
     } else {
         $y = substr($month, 0, 4);
         $m = substr($month, 4, 2);
         $time = mktime(0, 0, 0, $m, 1, $y);
     }
     $date = new DateTime(array($time));
     $c = new Calendar();
     $date->resetToFirst();
     $days = $date->getLastDay();
     $start_days = $date->getDayOfWeek() - 1;
     // days needed to pad beginning
     $date_prev_month = clone $date;
     $date_prev_month->adjustMonth(-1);
     $date_prev_month->resetToLast();
     $date_prev_month->adjustDay(($start_days - 1) * -1);
     $date_next_month = clone $date;
     $date_next_month->adjustMonth(1);
     $e = Model::load('Event');
     $events = $e->getEvents(false, $date_prev_month, $date_next_month);
     $month = $c->newBuildByMonth($date_prev_month->getDay(), $date_prev_month->getMonth(), $date_prev_month->getYear(), $date_prev_month->getLastDay(), $date->getLastDay(), $events);
     $this->assign('month', $date->getMonthText());
     $this->assign('year', $date->getYear());
     $this->assign('current_month', vsprintf("%02d", $date->getMonth()));
     $this->assign('cal_month', $month);
     if ($date->getMonth() == 12) {
         $next_month_link = $date->getYear() . '01';
     } else {
         $next_month_link = $date->getYear() . vsprintf("%02d", $date->getMonth() + 1);
     }
     if ($date->getMonth() == 1) {
         $prev_month_link = $date->getYear() . '12';
     } else {
         $prev_month_link = $date->getYear() . vsprintf("%02d", $date->getMonth() - 1);
     }
     $this->assign('prev_month_link', $prev_month_link);
     $this->assign('next_month_link', $next_month_link);
     $prev_year_link = $date->getYear() - 1 . vsprintf("%02d", $date->getMonth());
     $next_year_link = $date->getYear() + 1 . vsprintf("%02d", $date->getMonth());
     $this->assign('prev_year_link', $prev_year_link);
     $this->assign('next_year_link', $next_year_link);
     $this->setTemplate('elib://admin/events_month.tpl');
 }