Skip to content

Instantly share code, notes, and snippets.

@chesster
Created December 3, 2014 13:24
Show Gist options
  • Save chesster/be5c71d147d4588bc09d to your computer and use it in GitHub Desktop.
Save chesster/be5c71d147d4588bc09d to your computer and use it in GitHub Desktop.
diff --git a/.gitignore b/.gitignore
index b1663e0..0447dea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,6 @@ data/*
www/data/*
www/tmp/*
ses_tmp/*
-config/bootstrap.local.*
+config/bootstrap.local.php
log/*
diff --git a/.htaccess b/.htaccess
index 3f0d108..f5074bc 100644
--- a/.htaccess
+++ b/.htaccess
@@ -2,7 +2,3 @@
RewriteEngine On
RewriteRule (.*)$ /www/$1
</IfModule>
-#AuthUserFile /var/www/stage_site1/html/.htpasswd
-#AuthName "Authorization Required"
-#AuthType Basic
-#require user staging
diff --git a/.htpasswd b/.htpasswd
deleted file mode 100644
index 5be57b5..0000000
--- a/.htpasswd
+++ /dev/null
@@ -1 +0,0 @@
-staging:$apr1$8N5a.fmW$FI2FNQO7Gk5q9Oe5YntCZ/
diff --git a/config/SiteController.class.php b/config/SiteController.class.php
index 131f828..e08edb3 100644
--- a/config/SiteController.class.php
+++ b/config/SiteController.class.php
@@ -24,6 +24,7 @@ class SiteController extends Controller {
}
public function before() {
+ parent::before();
$short_class = strtolower(str_replace('Controller', '', get_class($this)));
if (!$this->Auth->isAuthMethod($short_class, $this->methodRequest)) {
Error::redirect(401);
diff --git a/config/bootstrap.php b/config/bootstrap.php
index 686ea41..af60d4c 100644
--- a/config/bootstrap.php
+++ b/config/bootstrap.php
@@ -8,25 +8,14 @@
date_default_timezone_set("Europe/Amsterdam");
-// Debug function
-function localdebug() { global $DEBUG_IPS; if(in_array(trim(Net::getIP()), $DEBUG_IPS)) { debug(func_get_args()); } }
-function debug() { ob_start(); $var = func_get_args(); call_user_func_array('var_dump', $var); echo '<pre>'.htmlentities(preg_replace(array("/ *=\>\n */"), array(" => "), ob_get_clean())).'</pre>';};
-
-define('DOCUMENT_ROOT', realpath(getcwd().'/../').'/');
-
-if (file_exists(DOCUMENT_ROOT . '/config/bootstrap.local.php'))
-{
- require_once DOCUMENT_ROOT . '/config/bootstrap.local.php';
-}
-else
-{
// ROOT
- define('DOMAIN', 'personalbodyplan.com');
+define('DOMAIN', 'personalbodyplan.dev');
define('IS_HTTPS', (isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"])));
define('PREFIX', '');
define('ROOT_URL', 'http'.(IS_HTTPS == 'on' ? "s" : "").'://'.DOMAIN.PREFIX.'/');
define('HTTP_ROOT_URL', 'http://'.DOMAIN.PREFIX.'/');
define('HTTPS_ROOT_URL', 'https://'.DOMAIN.PREFIX.'/');
+define('DOCUMENT_ROOT', realpath(getcwd().'/../').'/');
define('SHOP_SERVER_IP', '192.168.0.10');
@@ -40,8 +29,8 @@ else
// Debug
$DEBUG_IPS = array('192.168.0.107', '193.172.124.133', '188.117.128.194');
define('MDB2_DEBUG', 0);
- define('DEBUG', 0);
- define('DEBUG_BACKTRACE', 0);
+define('DEBUG', 1);
+define('DEBUG_BACKTRACE', 1);
// State
define('BETA', 0);
@@ -67,6 +56,12 @@ else
define('GCM_PROJECT_ID', "907261884423");
define('GCM_KEY', "AIzaSyAjtuJIRCTS5xTQiz-sg2C00Vf5W2eTQw8");
+/*
+define('APN_SANDBOX', true);
+define('APN_CERT', DOCUMENT_ROOT.'config/push_certs/ck.pem');
+define('APN_PASSPHRASE', 'l@@tj3h0r3n');
+*/
+
// SMTP / Mail
define('ADMIN_MAIL', '[email protected]');
@@ -95,7 +90,8 @@ else
// Ideal Credentials
define('IDEAL_ENABLED', false);
- define('IDEAL_TEST_MODE', false);
+define('IDEAL_TEST_MODE', true);
+// define('IDEAL_TEST_MODE', false);
define('IDEAL_AQUIRER', 'Rabobank'); // Use Rabobank, ABN Amro, ING Bank or Simulator
define('IDEAL_MERCHANT_ID', '');
define('IDEAL_PRIVATE_KEY', '');
@@ -114,9 +110,14 @@ else
// OAuth
define('OAUTH_SALT', '23)$@#$ked@*!@)k1d-d1dk,s12kE');
- // define('ENORMAIL_API_KEY', '2b279a8ce9e564f6d597da011d653ce2');
+
define('ENORMAIL_API_KEY', 'c1f31c25912709abb16bdd84fd4c7ac0');
- define('ENORMAIL_EBOOK_LIST_KEY', '8c5a0ce8ed3a1e906ffb231c70270699');
- define('ENORMAIL_NEWSLETTER_FORM_KEY', '2b279a8ce9e564f6d597da011d653ce2');
+
+
+// Debug function
+function localdebug() { global $DEBUG_IPS; if(in_array(trim(Net::getIP()), $DEBUG_IPS)) { debug(func_get_args()); } }
+function debug() { ob_start(); $var = func_get_args(); call_user_func_array('var_dump', $var); echo '<pre>'.htmlentities(preg_replace(array("/ *=\>\n */"), array(" => "), ob_get_clean())).'</pre>';};
+if (file_exists(DOCUMENT_ROOT . '/config/bootstrap.local.php')) {
+ require_once DOCUMENT_ROOT . '/config/bootstrap.local.php';
}
?>
diff --git a/controller/admin/faq.php b/controller/admin/faq.php
index e35b4c4..c37d283 100644
--- a/controller/admin/faq.php
+++ b/controller/admin/faq.php
@@ -101,7 +101,7 @@ class FaqController extends SiteController {
));
}
- public function index_category($category_id=null) {
+ public function index_category($category_id) {
if (isset($this->data)) {
$current_order = $this->Faq->getKeyPairedBy(array('category_id' => $category_id), array('fields' => array('id', 'n'), 'order' => 'n'), 'faq_questions');
$changes = $this->Faq->getOrderChanges($current_order, $this->data);
@@ -169,7 +169,7 @@ class FaqController extends SiteController {
$this->set(compact('categories', 'question'));
}
- public function delete_question($question_id=null) {
+ public function delete_question($question_id) {
$this->Faq->delete(array('id' => $question_id), 'faq_questions');
Net::redirect(ROOT_URL . 'admin/faq', array(
'notify' => array(
diff --git a/controller/admin/forum.php b/controller/admin/forum.php
index 6df6266..854a7ce 100644
--- a/controller/admin/forum.php
+++ b/controller/admin/forum.php
@@ -186,7 +186,7 @@ class ForumController extends SiteController {
$this->set(compact('category'));
}
- public function delete_category($category_id=null) {
+ public function delete_category($category_id) {
$category_id = Filter::int($category_id);
$category = $this->Forum->getRowBy(array(
@@ -227,7 +227,7 @@ class ForumController extends SiteController {
}
}
- public function index_category($category_id=null) {
+ public function index_category($category_id) {
$category_id = Filter::int($category_id);
$category = $this->Forum->getRowBy(array(
'id' => $category_id), NULL, 'community_forum_categories');
@@ -358,7 +358,7 @@ class ForumController extends SiteController {
} */
- public function delete_thread($thread_id=null) {
+ public function delete_thread($thread_id) {
$thread_id = Filter::int($thread_id);
$thread = $this->Forum->getRowBy(array(
@@ -392,7 +392,7 @@ class ForumController extends SiteController {
}
}
- public function index_thread($thread_id=null) {
+ public function index_thread($thread_id) {
$thread_id = Filter::int($thread_id);
$thread = $this->Forum->getRowBy(array(
@@ -533,7 +533,7 @@ class ForumController extends SiteController {
} */
- public function delete_post($post_id=null) {
+ public function delete_post($post_id) {
$post_id = Filter::int($post_id);
$post = $this->Forum->getRowBy(array(
@@ -726,7 +726,7 @@ class ForumController extends SiteController {
* ********** AJAX FUNCTIONS ***********************************************************************************************
* *********************************************************************************************************************** */
- public function ajax_remove_violation($postId=null) {
+ public function ajax_remove_violation($postId) {
$this->isAjaxCall();
$ajax = false;
diff --git a/controller/admin/groups.php b/controller/admin/groups.php
index 9a36b84..e930642 100644
--- a/controller/admin/groups.php
+++ b/controller/admin/groups.php
@@ -28,7 +28,7 @@ class GroupsController extends SiteController {
* ********** PUBLIC FUNCTIONS (viewable) **********************************************************************************
* *********************************************************************************************************************** */
- public function close($group_id=null) {
+ public function close($group_id) {
$this->Groups->update(array('full' => 1), array('id' => $group_id), 'groups');
Net::redirect(ROOT_URL . 'admin/groups/index', array(
diff --git a/controller/admin/nutrition.php b/controller/admin/nutrition.php
index e5c8456..faa8f34 100644
--- a/controller/admin/nutrition.php
+++ b/controller/admin/nutrition.php
@@ -108,7 +108,7 @@ class NutritionController extends SiteController {
$this->setLayoutVar('pageTitle', 'Gebruikersmaaltijdfoto\'s');
}
- public function delete_recipe($recipe_id=null) {
+ public function delete_recipe($recipe_id) {
$this->Nutrition->delete(array(
'id' => $recipe_id), 'nutrition_recipes');
$file_path = DOCUMENT_ROOT . 'www/data/recipes/' . $recipe_id . '/';
@@ -559,7 +559,7 @@ class NutritionController extends SiteController {
$this->set(compact('nutrients', 'sub_nutrients', 'codeobj', 'genders', 'targets', 'bodyshapes', 'product', 'allergies'));
}
- public function delete_product($product_id=null) {
+ public function delete_product($product_id) {
$this->Nutrition->delete(array(
'id' => $product_id), 'nutrition_nutrients_products');
$this->Nutrition->delete(array(
@@ -634,7 +634,7 @@ class NutritionController extends SiteController {
$this->set(compact('nutrient', 'breadcrums'));
}
- public function index_sub_nutrients($nutrient_id=null) {
+ public function index_sub_nutrients($nutrient_id) {
$nutrient = $this->Nutrition->getRowBy(array(
'id' => $nutrient_id), NULL, 'nutrition_nutrients');
if (!$nutrient) {
@@ -691,7 +691,7 @@ class NutritionController extends SiteController {
$this->setLayoutVar('pageTitle', 'Sub-nutri&euml;nten: ' . $nutrient['name']);
}
- public function edit_sub_nutrient($nutrient_id=null, $sub_nutrient_id = 0) {
+ public function edit_sub_nutrient($nutrient_id, $sub_nutrient_id = 0) {
$sub_nutrient_id = Filter::int($sub_nutrient_id);
if (isset($this->data)) {
@@ -756,7 +756,7 @@ class NutritionController extends SiteController {
$this->set(compact('sub_nutrient', 'nutrients', 'breadcrums'));
}
- public function delete_sub_nutrient($sub_nutrient_id=null) {
+ public function delete_sub_nutrient($sub_nutrient_id) {
$sub_nutrient_id = Filter::int($sub_nutrient_id);
$sub_nutrient = $this->Nutrition->getRowBy(array(
'id' => $sub_nutrient_id), NULL, 'nutrition_nutrients_sub');
@@ -811,7 +811,7 @@ class NutritionController extends SiteController {
$this->setLayoutVar('pageTitle', 'Community recepten');
}
- public function view_community_recipe($recipe_id=null) {
+ public function view_community_recipe($recipe_id) {
$mealtypes = $this->Nutrition->getKeyPairedBy(NULL, array(
'fields' => array(
'id',
diff --git a/controller/admin/pages.php b/controller/admin/pages.php
index 57d1fdc..4f3e7f6 100644
--- a/controller/admin/pages.php
+++ b/controller/admin/pages.php
@@ -60,7 +60,7 @@ class PagesController extends SiteController {
$this->set(compact('pagination', 'paginated'));
}
- public function edit($id=null) {
+ public function edit($id) {
$id = Filter::int($id);
$item = $this->Pages->getRowBy(array('id' => $id));
@@ -96,7 +96,7 @@ class PagesController extends SiteController {
* ********** AJAX FUNCTIONS ***********************************************************************************************
* *********************************************************************************************************************** */
- public function ajax_set_option($key=null, $value=null) {
+ public function ajax_set_option($key, $value) {
$this->isAjaxCall();
$ajax = false;
diff --git a/controller/admin/recovery.php b/controller/admin/recovery.php
index 071e1ec..dd8d1c7 100644
--- a/controller/admin/recovery.php
+++ b/controller/admin/recovery.php
@@ -41,7 +41,7 @@ class RecoveryController extends SiteController {
$this->setLayoutVar('pageTitle', 'Supplementen');
}
- public function edit($supplement_id=null) {
+ public function edit($supplement_id) {
if (isset($this->data)) {
$save = array(
'title' => $this->data['title'],
@@ -107,7 +107,7 @@ class RecoveryController extends SiteController {
$this->setLayoutVar('pageTitle', 'Supplementen per hormoon');
}
- public function edit_supplement_hormone($gender=null, $hormone=null, $iteration=null, $supplement_hormone_id = 0) {
+ public function edit_supplement_hormone($gender, $hormone, $iteration, $supplement_hormone_id = 0) {
$program = array(
'gender' => $gender,
@@ -158,7 +158,7 @@ class RecoveryController extends SiteController {
$this->set(compact('supplements', 'program'));
}
- public function delete_supplement_hormone($gender=null, $hormone=null, $iteration=null, $supplement_hormone_id=null) {
+ public function delete_supplement_hormone($gender, $hormone, $iteration, $supplement_hormone_id) {
$program = array(
'gender' => $gender,
'hormone' => $hormone,
diff --git a/controller/admin/secure.php b/controller/admin/secure.php
index 843f131..e56809b 100644
--- a/controller/admin/secure.php
+++ b/controller/admin/secure.php
@@ -23,7 +23,7 @@ class SecureController extends SiteController {
* ********** PUBLIC FUNCTIONS (viewable) **********************************************************************************
* *********************************************************************************************************************** */
- public function measurements($subscription_id=null, $file=null) {
+ public function measurements($subscription_id, $file) {
$this->attachModel(array('Users'));
$source = DOCUMENT_ROOT . 'data/measurements/' . $subscription_id . '/' . $file;
@@ -36,7 +36,7 @@ class SecureController extends SiteController {
exit();
}
- public function behavior_challenge($subscription_id=null, $file=null) {
+ public function behavior_challenge($subscription_id, $file) {
$this->attachModel(array('Users'));
$source = DOCUMENT_ROOT . 'data/behavior/' . $subscription_id . '/' . $file;
diff --git a/controller/admin/subscriptions.php b/controller/admin/subscriptions.php
index 81fdbd9..a3317a5 100644
--- a/controller/admin/subscriptions.php
+++ b/controller/admin/subscriptions.php
@@ -46,7 +46,7 @@ class SubscriptionsController extends SiteController {
* ********** PUBLIC FUNCTIONS (viewable) **********************************************************************************
* *********************************************************************************************************************** */
- public function view($subscription_id=null, $page = '') {
+ public function view($subscription_id, $page = '') {
unset($_SESSION['days']); // UNSET REMEMBERED DAYS FROM PREVIOUS USERS (general->getday());
$this->set(compact('page'));
@@ -293,7 +293,7 @@ class SubscriptionsController extends SiteController {
}
}
- public function change_code($subscription_id=null) {
+ public function change_code($subscription_id) {
$subscription_id = Filter::int($subscription_id);
$subscription = $this->Subscriptions->getRowBy(array('us.id' => $subscription_id), array(
@@ -379,7 +379,7 @@ class SubscriptionsController extends SiteController {
$this->set(compact('subscription', 'codeobj'));
}
- public function create_subscription($subscription_id=null, $payed_type=null, $months=null) {
+ public function create_subscription($subscription_id, $payed_type, $months) {
$this->attachModel(array('Users'));
$subscription_id = Filter::int($subscription_id, true);
@@ -433,7 +433,7 @@ class SubscriptionsController extends SiteController {
));
}
- public function do_payment($payment_id=null, $type=null) {
+ public function do_payment($payment_id, $type) {
$this_payment_id = '';
if ($type == 'gift') {
$this_payment_id = '00000';
@@ -461,7 +461,7 @@ class SubscriptionsController extends SiteController {
}
}
- public function set_budget($subscription_id=null) {
+ public function set_budget($subscription_id) {
$saved = false;
if(isset($this->data)) {
$this->attachModel(array('Nutrition'));
diff --git a/controller/admin/system.php b/controller/admin/system.php
index 3210c72..cce8eb6 100644
--- a/controller/admin/system.php
+++ b/controller/admin/system.php
@@ -267,7 +267,7 @@ class SystemController extends SiteController {
die();
}
- public function take_over($user_id=null) {
+ public function take_over($user_id) {
$_SESSION['admin'] = $this->Auth->user;
$this->Auth->user['id'] = $user_id;
$this->Auth->updateUser();
diff --git a/controller/admin/training.php b/controller/admin/training.php
index 03b84e6..369a630 100644
--- a/controller/admin/training.php
+++ b/controller/admin/training.php
@@ -46,7 +46,7 @@ class TrainingController extends SiteController {
* ********** PUBLIC FUNCTIONS (viewable) **********************************************************************************
* *********************************************************************************************************************** */
- public function index($program_code=null) {
+ public function index($program_code) {
$this->setLayoutVar('pageTitle', 'Trainingschema\'s');
Loader::lib(array('PBP'), 'pbp');
@@ -223,13 +223,13 @@ class TrainingController extends SiteController {
$this->set(compact('exercise'));
}
- public function schedule_index($schedule_id=null) {
+ public function schedule_index($schedule_id) {
$training = $this->Training->getScheduleById($schedule_id);
$this->set(compact('training'));
}
- public function index_descriptions($type=null) {
+ public function index_descriptions($type) {
$perpage = 20;
$pagination = $this->getPagination(array('order' => 'title', 'direction' => 'ASC'));
@@ -254,11 +254,11 @@ class TrainingController extends SiteController {
$this->set(compact('pagination', 'paginated', 'type'));
}
- public function strToHandle($str='') {
+ public function strToHandle($str) {
return trim(strtolower(str_replace(array(' '), array(''), $str)));
}
- public function edit_description($type=null, $id=null) {
+ public function edit_description($type, $id) {
$id = Filter::int($id);
switch ($type) {
@@ -306,7 +306,7 @@ class TrainingController extends SiteController {
$this->set(compact('item', 'type'));
}
- public function delete_description($type=null, $id=null) {
+ public function delete_description($type, $id) {
$id = Filter::int($id);
switch ($type) {
@@ -329,7 +329,7 @@ class TrainingController extends SiteController {
));
}
- public function availability($program_code=null) {
+ public function availability($program_code) {
$this->setLayoutVar('pageTitle', 'Beschikbaarheid van trainingsschema\'s');
Loader::lib(array('PBP'), 'pbp');
@@ -372,7 +372,7 @@ class TrainingController extends SiteController {
$this->set(compact('codeobj', 'code', 'fases', 'methods'));
}
- public function new_schedule($program_code=null) {
+ public function new_schedule($program_code) {
$this->view = 'edit_schedule';
$program = unserialize(base64_decode($program_code));
@@ -450,7 +450,7 @@ class TrainingController extends SiteController {
* *********************************************************************************************************************** */
// Checks consequences to other schedules, user progress and user continuity. Can delete affected progress if param set.
- private function get_consequences($trainingscode_id=null, $weeks=null, $delete = false) {
+ private function get_consequences($trainingscode_id, $weeks, $delete = false) {
$this->attachModel(array('Codes', 'Subscriptions'));
// Get schedule IDs for code
diff --git a/controller/admin/users.php b/controller/admin/users.php
index 0bd8381..bb8022e 100644
--- a/controller/admin/users.php
+++ b/controller/admin/users.php
@@ -260,7 +260,7 @@ class UsersController extends SiteController {
$this->set(compact('lists', 'groups'));
}
- public function index($type=null) {
+ public function index($type) {
$perpage = 15;
$pagination = $this->getPagination(array('order' => 'first_name', 'direction' => 'ASC'));
$filter = array(
@@ -405,7 +405,7 @@ class UsersController extends SiteController {
$this->set(compact('pagination', 'paginated', 'filter', 'groups', 'type'));
}
- public function set_status($user_id=null, $status=null) {
+ public function set_status($user_id, $status) {
$status = Filter::int($status);
if ($status != 0)
$status = 1;
@@ -420,12 +420,12 @@ class UsersController extends SiteController {
));
}
- public function view_current_subscription($user_id=null, $page = '') {
+ public function view_current_subscription($user_id, $page = '') {
$this->viewCurrentSubscription($user_id, NULL, $page);
exit();
}
- private function viewCurrentSubscription($user_id=null, $message = NULL, $page = '') {
+ private function viewCurrentSubscription($user_id, $message = NULL, $page = '') {
$user_id = Filter::int($user_id);
if ($user_id != 0) {
$subscription_id = $this->Users->getOneBy(array('uc.user_id' => $user_id), array('fields' => array('uc.last_subscription_id')), 'users_clients uc');
@@ -464,7 +464,7 @@ class UsersController extends SiteController {
}
*/
- public function set_coach($user_id=null) {
+ public function set_coach($user_id) {
$this->setLayoutVar('pageTitle', 'Coach kiezen');
if (isset($this->data['coach_id'])) {
$this->Users->delete(array('user_id' => $user_id), 'users_coaches');
diff --git a/controller/api.php b/controller/api.php
index f45af4b..b1d4785 100644
--- a/controller/api.php
+++ b/controller/api.php
@@ -1,7 +1,5 @@
<?php
-error_reporting(0);
-
/**
* ApiController
* @author Artificial Industry
@@ -91,10 +89,6 @@ class ApiController extends SiteController {
$this->isAjaxCall();
}
- public function before() {
- }
-
-
/*
* *************************************************************************************************************************
* ********** PUBLIC FUNCTIONS (viewable) **********************************************************************************
@@ -2170,83 +2164,4 @@ class ApiController extends SiteController {
}
-// /**
-// * VersionizedApiController
-// * @package pbp
-// * @subpackage controller
-// */
-//
-// require_once(DOCUMENT_ROOT . 'controller/api/api_v1_0_0.php');
-// require_once(DOCUMENT_ROOT . 'controller/api/api_v1_1_0.php');
-//
-// class VersionizedApiController extends SiteController {
-//
-// private static $API_VERSIONS = array(
-// '1.0.0' => 'ApiV1_0_0Controller',
-// '1.1.0' => 'ApiV1_1_0Controller'
-// );
-//
-// public function __construct() {
-// parent::__construct();
-//
-// header('Content-Type: application/json');
-// $_SESSION['login_current_subscription'] = true;
-//
-// $oauth = Loader::component('OAuth');
-// $token = $oauth->verifyToken();
-//
-// $this->_create_methods();
-//
-// if (!$token) {
-// echo json_encode(array(
-// 'error' => 'no_token',
-// 'error_description' => 'Token incorrect'));
-// die();
-// } else {
-// if (!$this->Auth->isAuth()) {
-// $_GET['grant_type'] = 'access_token';
-// if (!$this->Auth->loginFromOAuth($_GET, $token)) {
-// echo json_encode(array(
-// 'error' => 'no_auth',
-// 'error_description' => 'Not authorized. No authorized user found in session'));
-// die();
-// }
-// }
-// }
-//
-// $this->isAjaxCall();
-// }
-//
-// public function before() {
-// }
-//
-// protected function _create_methods() {
-//
-// // I know this is a bit hackish, but I have to make do with what I have.
-// // The Idea is to "fake inharite" this class with a perticular version of the API
-// // The "inharited" class has to have the same parent as this one and basically
-// // not do anything "fancy" within its methods, like operating on a "never before seen"
-// // property. Also remember that this is a copy of a method: do not manipulate the objects
-// // properties in the "inherited" class.
-//
-// $this->attachModel('Api');
-// $apiModel = $this->Api;
-// $api_object_name = isset(self::$API_VERSIONS[$this->Api->getCurrentApiVersion()])
-// ? self::$API_VERSIONS[$this->Api->getCurrentApiVersion()]
-// : self::$API_VERSIONS[$apiModel::DEFAULT_API_VERSION];
-//
-// // Not working 'couse of routing: @TODO: investigate.
-// // runkit_class_adopt($api_object_name, get_class($this));
-//
-// $class_name = get_class($this);
-// $api_object = new $api_object_name();
-// self::$roles = $api_object_name::$roles;
-// foreach ($api_object_name::$roles[0]['methods'] as $method_name) {
-// if(!method_exists($this, $method_name) && method_exists($api_object, $method_name)) {
-// runkit_method_copy($class_name, $method_name, $api_object_name, $method_name);
-// }
-// }
-// }
-// }
-
?>
diff --git a/controller/articles.php b/controller/articles.php
index 5d7ba58..63ea5e7 100644
--- a/controller/articles.php
+++ b/controller/articles.php
@@ -85,7 +85,7 @@ class ArticlesController extends SiteController {
$this->set(compact('paginated', 'category', 'pagination', 'order'));
}
- public function view($article_id=null) {
+ public function view($article_id) {
$this->layout = 'default_responsive';
$article_id = Filter::int($article_id);
$article = $this->Articles->getArticle($article_id);
@@ -177,7 +177,7 @@ class ArticlesController extends SiteController {
$this->set(compact('ajax'));
}
- public function ajax_update_shares($article_id=null) {
+ public function ajax_update_shares($article_id) {
$this->isAjaxCall();
$ajax = false;
diff --git a/controller/behavior.php b/controller/behavior.php
index c037454..d85aff0 100644
--- a/controller/behavior.php
+++ b/controller/behavior.php
@@ -112,7 +112,7 @@ class BehaviorController extends SiteController {
$this->set(compact('habits', 'progress'));
}
- public function habit($habit_id=null) {
+ public function habit($habit_id) {
$habit_id = Filter::int($habit_id);
$day = $this->General->getDay($this->Auth->user['subscription_id']);
@@ -137,7 +137,7 @@ class BehaviorController extends SiteController {
$this->set(compact('habit', 'lessons', 'habits', 'breadcrums'), false);
}
- public function lesson($habit_id=null, $lesson_num=null) {
+ public function lesson($habit_id, $lesson_num) {
$lesson_num = Filter::int($lesson_num);
$habit_id = Filter::int($habit_id);
diff --git a/controller/faq.php b/controller/faq.php
index 355f69d..8ed7b5c 100644
--- a/controller/faq.php
+++ b/controller/faq.php
@@ -65,7 +65,7 @@ class FaqController extends SiteController {
* ********** AJAX FUNCTIONS ***********************************************************************************************
* *********************************************************************************************************************** */
- public function ajax_get_answer($question_id=null) {
+ public function ajax_get_answer($question_id) {
$this->isAjaxCall();
$ajax = $this->Faq->getRowBy(array('id' => $question_id), NULL, 'faq_questions');
$this->set(compact('ajax'));
diff --git a/controller/forum.php b/controller/forum.php
index e6f68f2..b847deb 100644
--- a/controller/forum.php
+++ b/controller/forum.php
@@ -69,7 +69,7 @@ class ForumController extends SiteController {
$this->set(compact('topics'));
}
- public function view_profile($user_id=null) {
+ public function view_profile($user_id) {
$profile = $this->Forum->getRowBy(
array('uc.user_id' => $user_id),
array(
@@ -86,7 +86,7 @@ class ForumController extends SiteController {
$this->set(compact('profile'));
}
- public function index_category($category_id=null) {
+ public function index_category($category_id) {
$category_id = Filter::int($category_id, true, true);
$category = $this->Forum->getRowBy(array('id' => $category_id), NULL, 'community_forum_categories');
@@ -120,7 +120,7 @@ class ForumController extends SiteController {
$this->setLayoutVar('pageTitle', 'Forum: ' . $category['title']);
}
- public function add_thread($category_id=null) {
+ public function add_thread($category_id) {
$category_id = Filter::int($category_id);
$category = $this->Forum->getRowBy(array('id' => $category_id), NULL, 'community_forum_categories');
@@ -194,7 +194,7 @@ class ForumController extends SiteController {
$this->set(compact('thread', 'post', 'breadcrums'));
}
- public function index_thread($thread_id=null) {
+ public function index_thread($thread_id) {
$thread_id = Filter::int($thread_id);
$thread = $this->Forum->getRowBy(array('id' => $thread_id), NULL, 'community_forum_threads');
@@ -234,7 +234,7 @@ class ForumController extends SiteController {
$this->setLayoutVar('pageTitle', 'Forum - Thread');
}
- public function add_post($thread_id=null) {
+ public function add_post($thread_id) {
$thread_id = Filter::int($thread_id);
$thread = $this->Forum->getRowBy(array('id' => $thread_id), NULL, 'community_forum_threads');
diff --git a/controller/mce.php b/controller/mce.php
index 2c637c7..d9c2ee9 100644
--- a/controller/mce.php
+++ b/controller/mce.php
@@ -130,7 +130,7 @@ class MCEController extends SiteController {
* ********** PRIVATE FUNCTIONS ********************************************************************************************
* *********************************************************************************************************************** */
- private function getImageSource($source=null) {
+ private function getImageSource($source) {
$source = array('source' => $source);
list($source['width'], $source['height'], $source['type']) = @getimagesize($source['source']);
@@ -151,7 +151,7 @@ class MCEController extends SiteController {
return $source;
}
- private function imageResizeBounding($source=null, $target=null) {
+ private function imageResizeBounding($source, $target) {
$dif_x = $source['width'] - $target['width'];
$dif_y = $source['height'] - $target['height'];
@@ -195,7 +195,7 @@ class MCEController extends SiteController {
$this->set(compact('ajax'));
}
- public function delete_category($category_id=null) {
+ public function delete_category($category_id) {
$this->isAjaxCall();
$ajax = true;
@@ -205,7 +205,7 @@ class MCEController extends SiteController {
$this->set(compact('ajax'));
}
- public function delete_image($image_id=null) {
+ public function delete_image($image_id) {
$this->isAjaxCall();
$ajax = true;
@@ -217,8 +217,9 @@ class MCEController extends SiteController {
$this->set(compact('ajax'));
}
- public function get_images($category_id=0) {
+ public function get_images($category_id) {
$this->isAjaxCall();
+
$ajax = $this->Mce->getImages($category_id);
$this->set(compact('ajax'));
diff --git a/controller/nutrition.php b/controller/nutrition.php
index 947f426..b721594 100644
--- a/controller/nutrition.php
+++ b/controller/nutrition.php
@@ -223,7 +223,7 @@ class NutritionController extends SiteController
$this->set(compact('nutrients', 'mealtypes', 'water', 'progress', 'day', 'method'));
}
- public function replace_suggestion($dayN=null, $type=null, $orderN=null, $fk=null, $mealtypeId = 0)
+ public function replace_suggestion($dayN, $type, $orderN, $fk, $mealtypeId = 0)
{
$allowedTypes = array(
'recipes',
@@ -265,7 +265,7 @@ class NutritionController extends SiteController
Net::redirect(ROOT_URL . 'nutrition/mealsuggestions/' . $dayN);
}
- public function mealsuggestions($dayN=null)
+ public function mealsuggestions($dayN)
{
if (isset($this->data['meals_per_day'])) {
$this->attachModel(array(
@@ -376,7 +376,7 @@ class NutritionController extends SiteController
$this->set(compact('breadcrums', 'recipes', 'mealtypes'));
}
- public function my_recipe_view($recipe_id=null)
+ public function my_recipe_view($recipe_id)
{
$recipe = $this->Nutrition->getCommunityRecipe($recipe_id, $this->Auth->user['id']);
@@ -578,7 +578,7 @@ class NutritionController extends SiteController
$this->set(compact('breadcrums', 'mealtypes', 'plates', 'portions'));
}
- public function products($nutrient_id=null)
+ public function products($nutrient_id)
{
$nutrients = $this->Nutrition->getKeyPairedBy(NULL, array(
'fields' => array(
@@ -630,7 +630,7 @@ class NutritionController extends SiteController
$this->set(compact('nutrient', 'nutrients', 'sub_nutrients', 'breadcrums'));
}
- public function product($product_id=null)
+ public function product($product_id)
{
$nutrients = $this->Nutrition->getKeyPairedBy(NULL, array(
'fields' => array(
@@ -659,7 +659,7 @@ class NutritionController extends SiteController
$this->set(compact('product', 'nutrients', 'breadcrums'));
}
- public function mealtype($mealtype_id=null)
+ public function mealtype($mealtype_id)
{
$this->attachModel(array(
'Users'));
@@ -743,13 +743,13 @@ class NutritionController extends SiteController
$this->set(compact('mealtype', 'recipes', 'mealtype_id', 'breadcrums', 'allergy_selection', 'allergies'));
}
- public function view_as_mealtype($mealtype_id=null, $recipe_id=null)
+ public function view_as_mealtype($mealtype_id, $recipe_id)
{
$_SESSION['last_mealtype_id'] = $mealtype_id;
Net::redirect(ROOT_URL . 'nutrition/view/' . $recipe_id);
}
- public function view($recipe_id=null)
+ public function view($recipe_id)
{
$recipe = $this->Nutrition->getRecipe($recipe_id);
diff --git a/controller/pages.php b/controller/pages.php
index 5e9563a..ca91300 100644
--- a/controller/pages.php
+++ b/controller/pages.php
@@ -74,7 +74,7 @@ class PagesController extends SiteController {
/**
* Sending Push Notification
*/
- public function send_notification($registration_ids=null, $message=null) {
+ public function send_notification($registration_ids, $message) {
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registration_ids,
@@ -161,7 +161,7 @@ class PagesController extends SiteController {
$this->layout = 'no_program';
}
- public function facebook_training($rating=null) {
+ public function facebook_training($rating) {
$this->setLayoutVar("pageTitle", "Ik heb getraind met Personal Body Plan");
$this->setLayoutVar("pageDescription", "Ik geef mijn training een " . $rating);
$this->setLayoutVar("pageImage", "assets/img/facebook_rating/level" . $rating . ".png");
diff --git a/controller/progress.php b/controller/progress.php
index a9350ca..521940d 100644
--- a/controller/progress.php
+++ b/controller/progress.php
@@ -53,7 +53,7 @@ class ProgressController extends SiteController
* ********** PUBLIC FUNCTIONS (viewable) **********************************************************************************
* *********************************************************************************************************************** */
- public function view($week=null)
+ public function view($week)
{
$this->setLayoutVar('selectedMenu', 'home');
$this->setLayoutVar('pageTitle', 'Progressie');
@@ -608,7 +608,7 @@ class ProgressController extends SiteController
$this->set(compact('ajax'));
}
- public function ajax_get_meal_progress($day=null)
+ public function ajax_get_meal_progress($day)
{
$this->isAjaxCall();
$ajax = false;
@@ -725,7 +725,7 @@ class ProgressController extends SiteController
$this->set(compact('ajax'));
}
- public function ajax_search_nutrients($category=null)
+ public function ajax_search_nutrients($category)
{
$this->isAjaxCall();
$ajax = false;
diff --git a/controller/recovery.php b/controller/recovery.php
index 5e7e314..17236bc 100644
--- a/controller/recovery.php
+++ b/controller/recovery.php
@@ -113,7 +113,7 @@ class RecoveryController extends SiteController {
$this->set(compact('supplements', 'progress', 'optional_progress', 'day'));
}
- public function supplement($supplement_id=null) {
+ public function supplement($supplement_id) {
$supplement = $this->Recovery->getRowBy(array('id' => $supplement_id), NULL, 'recovery_supplements');
if (!$supplement)
Net::redirect(ROOT_URL . 'recovery');
diff --git a/controller/results.php b/controller/results.php
index 0d0516a..66ce7c0 100644
--- a/controller/results.php
+++ b/controller/results.php
@@ -56,7 +56,7 @@ class ResultsController extends SiteController {
* ********** AJAX FUNCTIONS ***********************************************************************************************
* *********************************************************************************************************************** */
- public function ajax_get_page($page=null) {
+ public function ajax_get_page($page) {
$this->isAjaxCall();
if (Filter::int($page, true) === false) {
@@ -79,7 +79,7 @@ class ResultsController extends SiteController {
$this->set(compact('ajax'), false);
}
- public function ajax_get_result($id=null) {
+ public function ajax_get_result($id) {
$this->isAjaxCall();
$ajax = $this->Results->getRowBy(array('id' => $id), NULL, 'results');
if ($ajax) {
diff --git a/controller/secure.php b/controller/secure.php
index 3a95c51..3b3d85a 100644
--- a/controller/secure.php
+++ b/controller/secure.php
@@ -23,7 +23,7 @@ class SecureController extends SiteController {
* ********** PUBLIC FUNCTIONS (viewable) **********************************************************************************
* *********************************************************************************************************************** */
- public function measurements($file=null) {
+ public function measurements($file) {
$this->attachModel(array('Users'));
if (!$this->Auth->isAuth()) {
die('401');
@@ -40,7 +40,7 @@ class SecureController extends SiteController {
exit();
}
- public function behavior_challenge($file=null) {
+ public function behavior_challenge($file) {
$this->attachModel(array('Users'));
if (!$this->Auth->isAuth()) {
die('401');
diff --git a/controller/subscriptions.php b/controller/subscriptions.php
index 8b087b1..1e31581 100644
--- a/controller/subscriptions.php
+++ b/controller/subscriptions.php
@@ -41,6 +41,9 @@ class SubscriptionsController extends SiteController {
parent::__construct();
}
+ public function before() {
+ parent::before();
+ }
/*
* *************************************************************************************************************************
@@ -523,7 +526,7 @@ class SubscriptionsController extends SiteController {
$this->set(compact('measurements'));
}
- public function change($subscription_id=null) {
+ public function change($subscription_id) {
$subscription_id = Filter::int($subscription_id);
if ($this->Subscriptions->getRowBy(array(
diff --git a/controller/team.php b/controller/team.php
index 91719bd..84c278d 100644
--- a/controller/team.php
+++ b/controller/team.php
@@ -45,7 +45,7 @@ class TeamController extends SiteController {
* ********** AJAX FUNCTIONS ***********************************************************************************************
* *********************************************************************************************************************** */
- public function ajax_get_member($member_id=null) {
+ public function ajax_get_member($member_id) {
$this->isAjaxCall();
$ajax = false;
diff --git a/controller/training.php b/controller/training.php
index 963567c..0402256 100644
--- a/controller/training.php
+++ b/controller/training.php
@@ -152,7 +152,7 @@ class TrainingController extends SiteController {
$this->set(compact('trainingdays', 'schedule_info', 'progress', 'day'));
}
- public function view($trainingday_n=null, $week_old = 0) {
+ public function view($trainingday_n, $week_old = 0) {
$day = $this->General->getDay($this->Auth->user['subscription_id']);
$trainingdays = $this->Training->getDaysInWeek($day, $this->Auth->user['program'], $this->Auth->user['subscription_id']);
@@ -176,7 +176,7 @@ class TrainingController extends SiteController {
$this->set(array('week' => $day['week']));
}
- public function print_view($trainingday_n=null, $week=null) {
+ public function print_view($trainingday_n, $week) {
$this->layout = 'print';
$day = $this->General->getDay($this->Auth->user['subscription_id']);
$trainingdays = $this->Training->getDaysInWeek($day, $this->Auth->user['program'], $this->Auth->user['subscription_id']);
@@ -197,7 +197,7 @@ class TrainingController extends SiteController {
$this->set(array('week' => $day['week']));
}
- public function exercise($exercise_id=null) {
+ public function exercise($exercise_id) {
$this->attachModel(array('Users'));
$instruction_gender = $this->Users->getOneBy(array('user_id' => $this->Auth->user['id']), array('fields' => array('instruction_gender')), 'users_clients');
diff --git a/controller/upload.php b/controller/upload.php
index d8787f9..cc37c9f 100644
--- a/controller/upload.php
+++ b/controller/upload.php
@@ -46,7 +46,7 @@ class UploadController extends SiteController {
* ********** PRIVATE FUNCTIONS ********************************************************************************************
* *********************************************************************************************************************** */
- private function file_upload_error_message($error_code=null) {
+ private function file_upload_error_message($error_code) {
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
return 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
diff --git a/core/Controller.class.php b/core/Controller.class.php
index e3c1147..af3ed29 100644
--- a/core/Controller.class.php
+++ b/core/Controller.class.php
@@ -63,8 +63,7 @@ class Controller {
* @uses AuthController::getInstance()
*/
public function __construct() {
- // if(isset($_REQUEST['data'])) $this->data = Sanitization::MYSQLsanitizeArray($_REQUEST['data']);
- if(isset($_REQUEST['data'])) $this->data = $_REQUEST['data'];
+ if(isset($_REQUEST['data'])) $this->data = Sanitization::MYSQLsanitizeArray($_REQUEST['data']);
$this->Auth = AuthController::getInstance();
$this->layout = (ADMINVIEW)? 'admin': 'default';
if(sizeof($this->uses) > 0) $this->attachModel($this->uses);
@@ -75,9 +74,9 @@ class Controller {
* Is always ran before first function call
*/
public function before() {
-# if (!in_array($this->methodRequest, $this->skipCSRFProtection)) {
-# CSRFProtection::validateAndRedirectAllPOST();
-# }
+ if (!in_array($this->methodRequest, $this->skipCSRFProtection)) {
+ CSRFProtection::validateAndRedirectAllPOST();
+ }
}
/**
@@ -151,8 +150,8 @@ class Controller {
$direction = ArrayHelper::getKey($_GET, 'd');
$default_direction = ArrayHelper::getKey($defaults, 'direction');
$pagination = array(
- 'order' => $order ? $order : ((isset($defaults['order']))?$defaults['order']:'DEFAULT'),
- 'page' => ($page && Filter::int($page, true, true)) ? $page : ((isset($defaults['page']))?$defaults['page']:1),
+ 'order' => $order ? $order : 'DEFAULT',
+ 'page' => ($page && Filter::int($page, true, true)) ? $page : 1,
'filter' => $filter ? $filter : '',
'direction' => ($direction && in_array(strtoupper($direction), array('ASC', 'DESC'))) ? $direction : ($default_direction ? $default_direction : 'DESC'),
);
diff --git a/lib/ai/CSRFProtection.class.php b/lib/ai/CSRFProtection.class.php
index 1763588..ca010dd 100644
--- a/lib/ai/CSRFProtection.class.php
+++ b/lib/ai/CSRFProtection.class.php
@@ -75,6 +75,7 @@ class CSRFProtection {
}
public function checkToken($timeout=NULL) {
+ // return true;
if (isset($_SESSION['csrf'])) {
if (!$this->checkTimeout($timeout)) {
return false;
diff --git a/lib/ai/Sanitization.class.php b/lib/ai/Sanitization.class.php
index 24e4c0f..1de8caa 100644
--- a/lib/ai/Sanitization.class.php
+++ b/lib/ai/Sanitization.class.php
@@ -36,13 +36,11 @@ class Sanitization
}
public static function HTMLsanitize($string) {
- return $string;
$string = htmlspecialchars_decode($string);
return htmlspecialchars($string);
}
public static function HTMLsanitizeArray($array) {
- return $array;
if (is_array($array)) {
foreach ($array as $key => $value) {
$array[$key] = Sanitization::HTMLsanitizeArray($value);
diff --git a/lib/secure_hash/new_secure_hash.class.php b/lib/secure_hash/new_secure_hash.class.php
index f7ec046..91b7498 100644
--- a/lib/secure_hash/new_secure_hash.class.php
+++ b/lib/secure_hash/new_secure_hash.class.php
@@ -7,44 +7,44 @@
require_once(DOCUMENT_ROOT . 'lib/secure_hash/secure_hash.class.php');
-# require_once (DOCUMENT_ROOT . 'vendor/autoload.php');
+require_once (DOCUMENT_ROOT . 'vendor/autoload.php');
class new_secure_hash extends secure_hash {
-# var $salt_len = 10;
-# var $hashing_method = 'blowfish';
-#
-# /**
-# * Plugin sha1 hashing method
-# * @access private
-# * @param string $str string to hash
-# * @param string $salt salt to use
-# * @param int $iter iterations to do
-# * @return string
-# */
-# function _hash_blowfish($str, $salt, $iter) {
-# $lib = new PasswordLib\PasswordLib();
-# return $lib->createPasswordHash($str);
-# }
-#
-# function _check($hash_formated, $pass) {
-# $password_array = explode($this->delimiter, $hash_formated);
-# list(,$hashing_method, $salt, $iter, $hash) = $password_array;
-# if ($hashing_method == 'blowfish') {
-# list(,$hashing_method,,,$m1,$m2,$m3,$hash) = $password_array;
-# $lib = new PasswordLib\PasswordLib();
-# return $lib->verifyPasswordHash($pass, $m1.'$'.$m2.'$'.$m3.'$'.$hash);
-# }
-# else {
-# $hm = $this->hashing_method;
-# $sl = $this->salt_len;
-# $this->hashing_method = $hashing_method;
-# $this->salt_len = strlen($salt);
-# $check = parent::check($hash_formated, $pass);
-# $this->hashing_method = $hm;
-# $this->salt_len = $sl;
-# return $check;
-# }
-# }
+ var $salt_len = 10;
+ var $hashing_method = 'blowfish';
+
+ /**
+ * Plugin sha1 hashing method
+ * @access private
+ * @param string $str string to hash
+ * @param string $salt salt to use
+ * @param int $iter iterations to do
+ * @return string
+ */
+ function _hash_blowfish($str, $salt, $iter) {
+ $lib = new PasswordLib\PasswordLib();
+ return $lib->createPasswordHash($str);
+ }
+
+ function check($hash_formated, $pass) {
+ $password_array = explode($this->delimiter, $hash_formated);
+ list(,$hashing_method, $salt, $iter, $hash) = $password_array;
+ if ($hashing_method == 'blowfish') {
+ list(,$hashing_method,,,$m1,$m2,$m3,$hash) = $password_array;
+ $lib = new PasswordLib\PasswordLib();
+ return $lib->verifyPasswordHash($pass, $m1.'$'.$m2.'$'.$m3.'$'.$hash);
+ }
+ else {
+ $hm = $this->hashing_method;
+ $sl = $this->salt_len;
+ $this->hashing_method = $hashing_method;
+ $this->salt_len = strlen($salt);
+ $check = parent::check($hash_formated, $pass);
+ $this->hashing_method = $hm;
+ $this->salt_len = $sl;
+ return $check;
+ }
+ }
}
diff --git a/view/subscriptions/admin/view.php b/view/subscriptions/admin/view.php
index abbfe61..8fa40d5 100644
--- a/view/subscriptions/admin/view.php
+++ b/view/subscriptions/admin/view.php
@@ -853,6 +853,7 @@
type: 'POST',
success: function(data) {
if (data) {
+ $('#message_list').append(html);
$('#mark_as_read').remove();
}
}
diff --git a/view/team/index.php b/view/team/index.php
index afff9aa..afb5ef0 100644
--- a/view/team/index.php
+++ b/view/team/index.php
@@ -217,12 +217,6 @@ $nBoxes = ceil(count($team) / 5) * 5;
e.preventDefault();
});
- <?php
- if ($team_id != 0) {
- echo "$('li[data-id=\"" . $team_id . "\"]').trigger('mousedown');";
- }
- ?>
-
$(window).resize(function() {
teamBlockHeight = $('#home-team .teammember.normal').width();
$('#home-team .teammember.normal').css({'height': teamBlockHeight});
diff --git a/www/index.php b/www/index.php
index a660374..e2d30bc 100644
--- a/www/index.php
+++ b/www/index.php
@@ -113,7 +113,7 @@ $controllerObj->before();
$r = new ReflectionMethod($controllerClass, $controllerAction);
$req_params_number = $r->getNumberOfRequiredParameters();
foreach ($route['args'] as $k => $value) {
- if ($value === null) {
+ if (!$value) {
unset($route['args'][$k]);
}
}
diff --git a/controller/admin/._messages.php b/controller/admin/._messages.php
index 027cfce..03c304e 100644
Binary files a/controller/admin/._messages.php and b/controller/admin/._messages.php differ
diff --git a/controller/api/api_v1_0_0.php b/controller/api/api_v1_0_0.php
index dee469f..c6042cd 100644
--- a/controller/api/api_v1_0_0.php
+++ b/controller/api/api_v1_0_0.php
@@ -26,7 +26,6 @@ class ApiV1_0_0Controller extends SiteController {
'message_to_coach',
'save_weekplan',
'save_progress_meal',
- 'generate_meal_suggestion',
'save_measurement',
'get_measurements',
'set_device_id',
@@ -44,218 +43,20 @@ class ApiV1_0_0Controller extends SiteController {
'use_coupon',
'use_credits',
'release_coupon',
- 'release_credits',
- 'get_product_info',
- 'get_recipe_info',
- 'search_products_meals',
- 'get_user_most_selected_nutrients',
- 'get_user_recent_nutrients',
- 'get_user_favorite_nutrients',
- 'set_activity_level',
- 'swap_meal_suggestion_part'
+ 'release_credits'
)
)
);
- var $userDataIsUpdated = false;
-
- public function __construct() {
- parent::__construct();
-
- header('Content-Type: application/json');
- $_SESSION['login_current_subscription'] = true;
-
- $oauth = Loader::component('OAuth');
- $token = $oauth->verifyToken();
-
- if (!$token) {
- echo json_encode(array(
- 'error' => 'no_token',
- 'error_description' => 'Token incorrect'));
- die();
- } else {
- if (!$this->Auth->isAuth()) {
- $_GET['grant_type'] = 'access_token';
- if (!$this->Auth->loginFromOAuth($_GET, $token)) {
- echo json_encode(array(
- 'error' => 'no_auth',
- 'error_description' => 'Not authorized. No authorized user found in session'));
- die();
- } else {
- $this->userDataIsUpdated = true;
- }
- }
- }
-
- $this->isAjaxCall();
- }
/*
* *************************************************************************************************************************
* ********** PUBLIC FUNCTIONS (viewable) **********************************************************************************
* *********************************************************************************************************************** */
- public function swap_meal_suggestion_part() {
- $data = false;
-
- if (isset($_REQUEST['day']) && isset($_REQUEST['type']) && isset($_REQUEST['order_n']) && isset($_REQUEST['fk']) && isset($_REQUEST['mealtype_id'])) {
- $dayN = Filter::int($_REQUEST['day']);
- $orderN = $_REQUEST['order_n'];
- $mealtypeId = $_REQUEST['mealtype_id'];
- $fk = $_REQUEST['fk'];
- $type = $_REQUEST['type'];
-
- $allowedTypes = array(
- 'recipes',
- 'supplements',
- 'fruits');
-
- if (in_array($type, $allowedTypes) && $dayN > 0) {
- $this->attachModel(array(
- 'Users',
- 'Nutrition'));
-
- $swap = array(
- 'day_n' => $dayN,
- 'type' => $type,
- 'order_n' => $orderN,
- 'fk' => $fk,
- 'mealtype_id' => $mealtypeId
- );
-
- // Get data
- $filter = array(
- 'allergies' => $this->Users->getColumnBy(array(
- 'user_id' => $this->Auth->user['id']), array(
- 'fields' => array(
- 'allergy_id')), 'users_allergies ua')
- );
- $budget = $this->Nutrition->getBudget($this->Auth->user['subscription_id'], $this->Auth->user['program'], $this->Nutrition->getSuggestionDayType($swap['day_n']));
- $selections = $this->Nutrition->getSuggestionSelections($this->Auth->user['program'], $filter, array(
- $swap['type']));
-
-
- $swapped = $this->Nutrition->swapSuggestion($this->Auth->user['subscription_id'], $budget, $selections, $swap);
- if ($swapped) {
- $suggestion = $this->Nutrition->getMealSuggestions($this->Auth->user['subscription_id'], $swap['day_n'], true);
- $data = array(
- 'nutrition_suggestions' => array(
- 'timestamp' => strtotime($suggestion['created']),
- 'data' => array(
- $suggestion)
- )
- );
- } else {
- $data = array(
- 'nutrition_suggestions' => array(
- 'timestamp' => time(),
- 'data' => false
- )
- );
- }
- }
- }
-
- if (!$data) {
- $this->set(array(
- 'ajax' => array(
- false)));
- } else {
- $this->set(array(
- 'ajax' => $data));
- }
- }
-
- public function generate_meal_suggestion() {
- $data = false;
-
- if (isset($_REQUEST['day']) && isset($_REQUEST['meals'])) {
- $day = Filter::int($_REQUEST['day']);
- $meals = Filter::int($_REQUEST['meals']);
-
- if ($meals >= 3 && $meals <= 6 && $day <= 6) {
- $this->attachModel(array(
- 'Nutrition',
- 'Users'));
-
- if ($day >= 4) {
- $type = 'training';
- } else {
- $type = 'normal';
- }
-
- $filter = array(
- 'allergies' => $this->Users->getColumnBy(array(
- 'user_id' => $this->Auth->user['id']), array(
- 'fields' => array(
- 'allergy_id')), 'users_allergies ua'));
- $budget = $this->Nutrition->getBudget($this->Auth->user['subscription_id'], $this->Auth->user['program'], $type);
- $selections = $this->Nutrition->getSuggestionSelections($this->Auth->user['program'], $filter);
-
- if ($budget && $selections) {
- $success = $this->Nutrition->generateMealSuggestions($this->Auth->user['subscription_id'], $this->Auth->user['program'], $budget, $selections, $meals, $day, $type);
- if ($success) {
- $suggestion = $this->Nutrition->getMealSuggestions($this->Auth->user['subscription_id'], $day, true);
- if ($suggestion) {
- $data = array(
- 'nutrition_suggestions' => array(
- 'timestamp' => strtotime($suggestion['created']),
- 'data' => array(
- $suggestion)
- )
- );
- }
- } else {
- $data = array(
- 'nutrition_suggestions' => array(
- 'timestamp' => time(),
- 'data' => false
- )
- );
- }
- }
- }
- }
-
- if (!$data) {
- $this->set(array(
- 'ajax' => array(
- $data)));
- } else {
- $this->set(array(
- 'ajax' => $data));
- }
- }
-
public function get_user_data() {
- $ajax = $this->getUserDataObject();
-
- $this->set(compact('ajax'));
- }
-
- private function getUserDataObject() {
$this->Auth->user['program']['start_day'] = $this->Auth->user['program']['start'];
- $user = $this->Auth->user;
-
- $this->attachModel(array(
- 'Users'));
- $user['birthdate'] = $this->Users->getOneBy(array(
- 'user_id' => $this->Auth->user['id']), array(
- 'fields' => array(
- 'birthdate')), 'users');
-
-
- unset($user['level']);
- unset($user['measurements']);
- unset($user['subscriptions']);
- unset($user['roles']);
- unset($user['forum_notification']);
- unset($user['need_progress']);
- unset($user['get_new_subscription']);
- unset($user['device_id']);
- unset($user['email']);
- unset($user['client']);
-
- return $user;
+ $ajax = $this->Auth->user;
+ $this->set(compact('ajax'));
}
public function get_user_address() {
@@ -399,14 +200,8 @@ class ApiV1_0_0Controller extends SiteController {
'Progress',
'Users',
'Subscriptions'));
-
- if (!$this->userDataIsUpdated) {
- $this->Auth->updateUser();
- }
-
$day = $this->General->getDay($this->Auth->user['subscription_id']);
-
// Is last "sync" or login in the right day?
$last_filled_day = $this->Progress->getLastFilledDay($this->Auth->user['subscription_id'], $day['n']);
if ($last_filled_day < $day['n']) {
@@ -418,8 +213,7 @@ class ApiV1_0_0Controller extends SiteController {
'device_id' => "",
'device_type' => "",
'schedule_id' => 0,
- 'schedule_timestamp' => 0,
- 'api_version' => 1
+ 'schedule_timestamp' => 0
);
$app_timestamps = array(
"training_exercises" => 0,
@@ -431,9 +225,6 @@ class ApiV1_0_0Controller extends SiteController {
"nutrition_nutrients" => 0,
"nutrition_portions" => 0,
"nutrition_meals_per_daytype" => 0,
- "nutrition_mealtypes_per_n" => 0,
- 'nutrition_suggestions' => 0,
- 'nutrition_caloriebudgets' => 0,
"week_plan" => 0,
"next_week_plan" => 0
);
@@ -501,16 +292,10 @@ class ApiV1_0_0Controller extends SiteController {
}
$handle = 'nutrition_products';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
- if ($app_state['api_version'] == 1) {
- $data[$handle] = array(
- 'timestamp' => $timestamps[$handle],
- 'data' => $this->Nutrition->getSortedProductsForProgramLegacy($this->Auth->user['program']));
- } else {
$data[$handle] = array(
'timestamp' => $timestamps[$handle],
'data' => $this->Nutrition->getSortedProductsForProgram($this->Auth->user['program']));
}
- }
$handle = 'nutrition_allergies';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
$data[$handle] = array(
@@ -522,47 +307,10 @@ class ApiV1_0_0Controller extends SiteController {
// - Update according to timestamped versions OR program (login)
$handle = 'nutrition_recipes';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
- if ($app_state['api_version'] == 1) {
- $data[$handle] = array(
- 'timestamp' => $timestamps[$handle],
- 'data' => $this->Nutrition->getAllRecipesForProgramLegacy($this->Auth->user['program']));
- } else {
$data[$handle] = array(
'timestamp' => $timestamps[$handle],
'data' => $this->Nutrition->getAllRecipesForProgram($this->Auth->user['program']));
}
- }
-
- // Caloriebudgets?
- $hasBudgets = false;
- switch ($this->Auth->user['nutrition_method']) {
- default:break;
- case "caloriecount":
- case "mealsuggestion":
- $handle = 'nutrition_caloriebudgets';
- $caloriebudget_timestamp = $this->Nutrition->fetchOne("SELECT UNIX_TIMESTAMP(`created`) FROM `subscriptions_caloriebudgets` WHERE `subscription_id` = " . $this->Auth->user['subscription_id'] . " ORDER BY `created` DESC LIMIT 0,1");
- if ($caloriebudget_timestamp) {
- $hasBudgets = true;
- }
- if ($hasBudgets && ($caloriebudget_timestamp == 0 || $app_timestamps[$handle] != $caloriebudget_timestamp)) {
- $budgetNormal = $this->Nutrition->getBudgetBase($this->Auth->user['subscription_id'], $this->Auth->user['program'], 'normal');
- $budgetTraining = $this->Nutrition->getBudgetBase($this->Auth->user['subscription_id'], $this->Auth->user['program'], 'training');
- if ($budgetNormal && $budgetTraining) {
- $data[$handle] = array(
- 'timestamp' => $caloriebudget_timestamp,
- 'data' => array(
- $budgetNormal,
- $budgetTraining
- )
- );
- }
- }
- break;
- }
-
- // Meals per day
- switch ($this->Auth->user['nutrition_method']) {
- case "hand":
$handle = 'nutrition_nutrients';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
$data[$handle] = array(
@@ -591,49 +339,12 @@ class ApiV1_0_0Controller extends SiteController {
'protein',
'fats')), 'nutrition_mealtypes_portions'));
}
-
$handle = 'nutrition_meals_per_daytype';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
$data[$handle] = array(
'timestamp' => $timestamps[$handle],
'data' => $this->Nutrition->getMealsPerDaytype($this->Auth->user['program']));
}
- break;
- case "caloriecount":
- $handle = "nutrition_mealtypes_per_n";
- if ($app_timestamps[$handle] != $timestamps[$handle]) {
- $meals = array(
- "training" => array(),
- "normal" => array());
-
- $meals["normal"][] = $this->Nutrition->getMealtypesForMealsPerDay(3, $this->Auth->user['program'], "normal");
- $meals["normal"][] = $this->Nutrition->getMealtypesForMealsPerDay(4, $this->Auth->user['program'], "normal");
- $meals["normal"][] = $this->Nutrition->getMealtypesForMealsPerDay(5, $this->Auth->user['program'], "normal");
- $meals["normal"][] = $this->Nutrition->getMealtypesForMealsPerDay(6, $this->Auth->user['program'], "normal");
-
- $meals["training"][] = $this->Nutrition->getMealtypesForMealsPerDay(3, $this->Auth->user['program'], "training");
- $meals["training"][] = $this->Nutrition->getMealtypesForMealsPerDay(4, $this->Auth->user['program'], "training");
- $meals["training"][] = $this->Nutrition->getMealtypesForMealsPerDay(5, $this->Auth->user['program'], "training");
- $meals["training"][] = $this->Nutrition->getMealtypesForMealsPerDay(6, $this->Auth->user['program'], "training");
-
- $data[$handle] = array(
- 'timestamp' => $timestamps[$handle],
- 'data' => $meals);
- }
-
- break;
- case "mealsuggestion":
- $handle = 'nutrition_suggestions';
- $suggestion_timestamp = $this->Nutrition->fetchOne("SELECT UNIX_TIMESTAMP(`created`) FROM `subscriptions_meal_suggestions` WHERE `subscription_id` = " . $this->Auth->user['subscription_id'] . " ORDER BY `created` DESC LIMIT 0,1");
-
- if ($hasBudgets && ($suggestion_timestamp == 0 || $app_timestamps[$handle] != $suggestion_timestamp)) {
- $data[$handle] = array(
- 'timestamp' => Filter::int($suggestion_timestamp),
- 'data' => $this->Nutrition->getAllMealSuggestions($this->Auth->user['subscription_id']));
- }
- break;
- }
-
$handle = 'recovery_supplements';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
$data[$handle] = array(
@@ -721,12 +432,10 @@ class ApiV1_0_0Controller extends SiteController {
$this->Users->update(array(
'device_id' => ''), array(
- 'device_id' => trim($app_state['device_id']),
- "device_type" => $device_type), 'users_clients');
+ 'device_id' => trim($app_state['device_id']), "device_type" => $device_type), 'users_clients');
$this->Users->update(array(
- 'device_id' => trim($app_state['device_id']),
- "device_type" => $device_type), array(
+ 'device_id' => trim($app_state['device_id']), "device_type" => $device_type), array(
'user_id' => $this->Auth->user['id']), 'users_clients');
}
@@ -757,8 +466,6 @@ class ApiV1_0_0Controller extends SiteController {
$data['now']['first_measurement'] = (isset($this->Auth->user['measurements']) && $this->Auth->user['measurements']['first']);
$data['now']['program_over'] = $this->Auth->user['program_over'];
- $data['userdata'] = $this->getUserDataObject();
-
$this->set(array(
'ajax' => $data));
}
@@ -823,36 +530,6 @@ class ApiV1_0_0Controller extends SiteController {
$this->set(compact('ajax'));
}
- public function get_product_info() {
- $ajax = false;
- if (isset($_REQUEST['id'])) {
- $product_id = Filter::int($_REQUEST['id']);
- $this->attachModel(array(
- 'Nutrition'));
- $data = $this->Nutrition->getProductWithNutrients($product_id, $this->Auth->user['program']);
- $this->set(array(
- 'ajax' => $data));
- } else {
- $this->set(array(
- 'ajax' => $ajax));
- }
- }
-
- public function get_recipe_info() {
- $ajax = false;
- if (isset($_REQUEST['id'])) {
- $product_id = Filter::int($_REQUEST['id']);
- $this->attachModel(array(
- 'Nutrition'));
- $data = $this->Nutrition->getRecipe($product_id, $this->Auth->user['program']);
- $this->set(array(
- 'ajax' => $data));
- } else {
- $this->set(array(
- 'ajax' => $ajax));
- }
- }
-
public function get_weekplan() {
$ajax = false;
@@ -1096,8 +773,6 @@ class ApiV1_0_0Controller extends SiteController {
}
public function save_progress_meal() {
- // TODO: Combine with save in ProgressController (same functionality)
-
$ajax = false;
if (isset($_REQUEST['text']) && isset($_REQUEST['time']) && isset($_REQUEST['mealtype_id']) && isset($_REQUEST['day'])) {
$this->attachModel(array(
@@ -1117,70 +792,19 @@ class ApiV1_0_0Controller extends SiteController {
$day_n = $day['n'] - 2;
break;
}
- $day_n = Filter::int($day_n);
if ($day_n < 1) {
$day_n = 1;
}
$time = $_REQUEST['time'];
$save = array(
- 'subscription_id' => $this->Auth->user['subscription_id'],
- 'day' => $day_n,
+ 'subscription_id' => Filter::int($this->Auth->user['subscription_id']),
+ 'day' => Filter::int($day_n),
'time' => $time,
'mealtype_id' => Filter::int($_REQUEST['mealtype_id']),
- 'description' => $_REQUEST['text'],
- 'has_nutrients' => 0
- );
-
- // save nutrients if send
- if (isset($_REQUEST['nutrients']) && is_array($_REQUEST['nutrients'])) {
- $nutrients_save = array();
- $save['has_nutrients'] = 1;
- foreach ($_REQUEST['nutrients'] as $nutrient) {
-
- $nutrient_save = array(
- 'subscription_id' => $this->Auth->user['subscription_id'],
- 'day' => $day_n,
- 'time' => $time,
- 'name' => $nutrient['name'],
- 'calories' => $nutrient['calories'],
- 'carbs' => $nutrient['carbs'],
- 'fats' => $nutrient['fats'],
- 'protein' => $nutrient['protein'],
- 'fibers' => $nutrient['fibers']
+ 'description' => $_REQUEST['text']
);
-
- switch ($nutrient['type']) {
- case 0:
- $nutrient_save['fk'] = $nutrient['product_id'];
- $nutrient_save['variety_id'] = $nutrient['variety_id'];
- $nutrient_save['type'] = 'product';
- break;
- case 1:
- $nutrient_save['fk'] = $nutrient['recipe_id'];
- $nutrient_save['variety_id'] = NULL;
- $nutrient_save['type'] = 'recipe';
- break;
- case 2:
- $nutrient_save['fk'] = NULL;
- $nutrient_save['variety_id'] = NULL;
- $nutrient_save['type'] = 'custom';
- break;
- }
- $nutrients_save[] = $nutrient_save;
- }
- }
-
$ajax = true;
-
- $time_str = str_replace(array(
- ':',
- ' '), array(
- '',
- ''), $time);
- $savename = $day_n . '_' . ( strlen($time_str) < 4 ? '0' . $time_str : $time_str) . '.jpg';
- $path = 'data/user_meals/' . $this->Auth->user['subscription_id'] . '/';
-
if (isset($_FILES)) {
Loader::lib(array(
'Image',
@@ -1201,6 +825,13 @@ class ApiV1_0_0Controller extends SiteController {
case "1": // gif
case "2": // jpg
case "3": // png
+ $path = 'data/user_meals/' . $this->Auth->user['subscription_id'] . '/';
+ $time_str = str_replace(array(
+ ':',
+ ' '), array(
+ '',
+ ''), $time);
+ $savename = $day_n . '_' . ( strlen($time_str) < 4 ? '0' . $time_str : $time_str) . '.jpg';
$this->Nutrition->saveProgressMealImage($doc, DOCUMENT_ROOT . 'www/' . $path, $savename);
File::deleteFiles(DOCUMENT_ROOT . 'www/tmp/', $file);
@@ -1216,34 +847,8 @@ class ApiV1_0_0Controller extends SiteController {
}
}
}
- } else {
- $file_path = DOCUMENT_ROOT . 'www/' . $path . $savename;
- if (file_exists($file_path)) {
- @unlink($file_path);
- }
}
-
$this->Progress->replace($save, 'progress_meals');
- if (isset($nutrients_save)) {
- $this->Progress->delete(array(
- 'subscription_id' => $this->Auth->user['subscription_id'],
- 'day' => $day_n,
- 'time' => $time), 'progress_nutrients');
-
- $this->Progress->insert($nutrients_save, 'progress_nutrients');
-
- if(isset($_REQUEST['favorite']) && trim($_REQUEST['favorite']) != "") {
- $favoriteName = ucwords(trim(preg_replace("/[^0-9a-zA-Z ]/", "", $_REQUEST['favorite'])));
- $this->Progress->replace(
- array(
- 'user_id' => $this->Auth->user['id'],
- 'name' => $favoriteName,
- 'subscription_id' => $this->Auth->user['subscription_id'],
- 'day' => $day_n,
- 'time' => $time
- ), 'users_favorite_meals');
- }
- }
}
if ($ajax) {
@@ -1751,54 +1356,6 @@ class ApiV1_0_0Controller extends SiteController {
$this->set(compact('ajax'));
}
- public function search_products_meals() {
- $this->attachModel(array(
- 'Nutrition'));
-
- $ajax = false;
-
- if (isset($_REQUEST['query'])) {
- $products = $this->Nutrition->searchProductsWithNutrients($_REQUEST['query']);
- $recipes = $this->Nutrition->searchRecipesWithNutrients($_REQUEST['query']);
- $ajax = array(
- 'products' => $products,
- 'recipes' => $recipes
- );
- }
-
- $this->set(compact('ajax'));
- }
-
- public function get_user_favorite_nutrients() {
- $this->attachModel(array(
- 'Nutrition'));
-
- $num_results = isset($_REQUEST['num_results']) && Filter::int($_REQUEST['num_results'], true) !== false ? Filter::int($_REQUEST['num_results'], true) : 20;
- $ajax = $this->Nutrition->getFavoriteNutrients($this->Auth->user['id'], $num_results);
-
- $this->set(compact('ajax'));
- }
-
- public function get_user_recent_nutrients() {
- $this->attachModel(array(
- 'Nutrition'));
-
- $num_results = isset($_REQUEST['num_results']) && Filter::int($_REQUEST['num_results'], true) !== false ? Filter::int($_REQUEST['num_results'], true) : 20;
- $ajax = $this->Nutrition->getRecentNutrients($this->Auth->user['subscription_id'], $num_results);
-
- $this->set(compact('ajax'));
- }
-
- public function get_user_most_selected_nutrients() {
- $this->attachModel(array(
- 'Nutrition'));
-
- $num_results = isset($_REQUEST['num_results']) && Filter::int($_REQUEST['num_results'], true) !== false ? Filter::int($_REQUEST['num_results'], true) : 20;
- $ajax = $this->Nutrition->getMostSelectedNutrients($this->Auth->user['subscription_id'], $num_results);
-
- $this->set(compact('ajax'));
- }
-
/*
* *************************************************************************************************************************
* ********** PRIVATE FUNCTIONS ********************************************************************************************
@@ -1867,6 +1424,47 @@ class ApiV1_0_0Controller extends SiteController {
return false;
}
+ /*
+ public function get_progress() {
+ $this->attachModel(array('Progress'));
+ $ajax = array();
+ $days = array();
+
+ if(isset($_REQUEST['days']) && is_array($_REQUEST['days'])) {
+ foreach($_REQUEST['days'] as $day) {
+ $day = Filter::int($day);
+
+ if($day != 0 && !in_array($day, $days)) {
+ $days[] = $day;
+ }
+ }
+
+ if(count($days) > 0) {
+ $ajax = $this->Progress->getDays($this->Auth->user['subscription_id'], date('Y-m-d', $this->Auth->user['program']['start']), $days);
+ }
+ }
+
+ $this->set(compact('ajax'));
+ }
+
+ public function get_training_progress() {
+ $this->attachModel('Training');
+ $ajax = array();
+
+ if(isset($_REQUEST['days']) && is_array($_REQUEST['days'])) {
+ foreach($_REQUEST['days'] as $day) {
+ $day = Filter::int($day);
+
+ if($day != 0 && !isset($ajax[$day])) {
+ $ajax[$day] = $this->Training->getTrainingFromProgress($this->Auth->user['subscription_id'], $day_n);
+ }
+ }
+ }
+
+ $this->set(compact('ajax'));
+ }
+ */
+
private function nullIsEmpty($str) {
if (strtolower($str) == "null") {
return "";
@@ -1920,7 +1518,7 @@ class ApiV1_0_0Controller extends SiteController {
}
if (isset($daydata['motivation_reason'])) {
- $reason = $this->nullIsEmpty($daydata['motivation_reason']);
+ $reason = $this->nullIsEmpty($daydata['training_reason']);
if ($reason != "") {
$save_reason[] = array(
'type' => 'motivation',
@@ -1932,12 +1530,12 @@ class ApiV1_0_0Controller extends SiteController {
}
if (isset($daydata['lesson_reason'])) {
- $reason = $this->nullIsEmpty($daydata['lesson_reason']);
+ $reason = $this->nullIsEmpty($daydata['training_reason']);
if ($reason != "") {
$save_reason[] = array(
'type' => 'habit',
'day' => $daydata['day'],
- 'subscription_id' => $this->Auth->user['subscription_id'],
+ 'subscription_id' => $this->Auth->user['subscriptionF_id'],
'reason' => $reason
);
}
@@ -2069,99 +1667,10 @@ class ApiV1_0_0Controller extends SiteController {
$array1 = $array2;
}
- public function set_activity_level() {
- $ajax = false;
- if (isset($_REQUEST['points'])) {
- $activityPoints = Filter::int($_REQUEST['points']);
-
- $this->attachModel(array(
- 'Subscriptions',
- 'Users',
- 'Nutrition'));
-
- if (isset($_REQUEST['birthdate'])) {
- $birthdate = $_REQUEST['birthdate'];
- $birthdateArr = explode('-', $birthdate);
- if (count($birthdateArr) == 3) {
- $this->Users->update(array(
- 'birthdate' => $birthdate), array(
- 'user_id' => $this->Auth->user['id']), 'users');
- }
- }
-
- $measurement = $this->Subscriptions->getLatestMeasurements($this->Auth->user['subscription_id']);
- $birthdate = $this->Users->getOneBy(array(
- 'user_id' => $this->Auth->user['id']), array(
- 'fields' => array(
- 'birthdate')), 'users');
-
- $sizes = array(
- 'height' => $measurement['height'],
- 'weight' => $measurement['weight'],
- 'age' => date_diff(new DateTime(), new DateTime($birthdate))->format('%y')
- );
-
- $day = $this->General->getDay($this->Auth->user['subscription_id']);
- $this->Nutrition->calculateBudget($this->Auth->user['subscription_id'], $this->Auth->user['program'], $sizes, $activityPoints, $day['week'], 'normal');
- $this->Nutrition->calculateBudget($this->Auth->user['subscription_id'], $this->Auth->user['program'], $sizes, $activityPoints, $day['week'], 'training');
-
- $data = array();
-
- // return new caloriebudget
- $budgetNormal = $this->Nutrition->getBudgetBase($this->Auth->user['subscription_id'], $this->Auth->user['program'], 'normal');
- $budgetTraining = $this->Nutrition->getBudgetBase($this->Auth->user['subscription_id'], $this->Auth->user['program'], 'training');
-
- $caloriebudget_timestamp = $this->Nutrition->fetchOne("SELECT UNIX_TIMESTAMP(`created`) FROM `subscriptions_caloriebudgets` WHERE `subscription_id` = " . $this->Auth->user['subscription_id'] . " ORDER BY `created` DESC LIMIT 0,1");
- if ($budgetNormal && $budgetTraining) {
- $handle = 'nutrition_caloriebudgets';
- $data[$handle] = array(
- 'timestamp' => $caloriebudget_timestamp,
- 'data' => array(
- $budgetNormal,
- $budgetTraining
- )
- );
-
- if ($this->Auth->user['nutrition_method'] == "mealsuggestion") {
-
- // Regenerate all suggestions
- $filter = array(
- 'allergies' => $this->Users->getColumnBy(array(
- 'user_id' => $this->Auth->user['id']), array(
- 'fields' => array(
- 'allergy_id')), 'users_allergies ua')
- );
-
- $selections = $this->Nutrition->getSuggestionSelections($this->Auth->user['program'], $filter);
- if ($selections) {
- $success = $this->Nutrition->generateAllMealSuggestions($this->Auth->user['subscription_id'], $this->Auth->user['program'], $budgetNormal, $budgetTraining, $selections, 4);
-
- $handle = 'nutrition_suggestions';
- if ($success) {
- $suggestion_timestamp = $this->Nutrition->fetchOne("SELECT UNIX_TIMESTAMP(`created`) FROM `subscriptions_meal_suggestions` WHERE `subscription_id` = " . $this->Auth->user['subscription_id'] . " ORDER BY `created` DESC LIMIT 0,1");
- $data[$handle] = array(
- 'timestamp' => $suggestion_timestamp,
- 'data' => $this->Nutrition->getAllMealSuggestions($this->Auth->user['subscription_id'])
- );
- } else {
- $suggestion_timestamp = 0;
- $data[$handle] = array(
- 'timestamp' => $suggestion_timestamp,
- 'data' => false
- );
- }
- }
- }
- }
-
- if (count($data) > 0) {
- $ajax = $data;
- }
-
- $this->set(compact('ajax'));
- }
- }
-
+ /*
+ * *************************************************************************************************************************
+ * ********** AJAX FUNCTIONS ***********************************************************************************************
+ * *********************************************************************************************************************** */
}
?>
diff --git a/lib/ai/._Apn.class.php b/lib/ai/._Apn.class.php
index 3131da3..8acc95b 100644
Binary files a/lib/ai/._Apn.class.php and b/lib/ai/._Apn.class.php differ
diff --git a/lib/secure_hash/new_secure_hash.class.php b/lib/secure_hash/new_secure_hash.class.php
index 91b7498..6118068 100644
--- a/lib/secure_hash/new_secure_hash.class.php
+++ b/lib/secure_hash/new_secure_hash.class.php
@@ -29,19 +29,19 @@ class new_secure_hash extends secure_hash {
function check($hash_formated, $pass) {
$password_array = explode($this->delimiter, $hash_formated);
- list(,$hashing_method, $salt, $iter, $hash) = $password_array;
- if ($hashing_method == 'blowfish') {
- list(,$hashing_method,,,$m1,$m2,$m3,$hash) = $password_array;
+ list(,$hashmethod, $salt, $iter, $hash) = $password_array;
+ if ($hashmethod == 'blowfish') {
+ list(,$hashmethod,,,$m1,$m2,$m3,$hash) = $password_array;
$lib = new PasswordLib\PasswordLib();
return $lib->verifyPasswordHash($pass, $m1.'$'.$m2.'$'.$m3.'$'.$hash);
}
else {
- $hm = $this->hashing_method;
+ $hm = $this->hashmethod;
$sl = $this->salt_len;
- $this->hashing_method = $hashing_method;
+ $this->hashmethod = $hashing_method;
$this->salt_len = strlen($salt);
$check = parent::check($hash_formated, $pass);
- $this->hashing_method = $hm;
+ $this->hashmethod = $hm;
$this->salt_len = $sl;
return $check;
}
diff --git a/migrations/001-api.sql b/migrations/001-api.sql
index 1b36d87..0beb4ed 100644
--- a/migrations/001-api.sql
+++ b/migrations/001-api.sql
@@ -1,11 +1,12 @@
use pbp;
CREATE TABLE IF NOT EXISTS `api_usage` (
- `user_id` int(10) unsigned NOT NULL,
- `device_id` varchar(255) NOT NULL DEFAULT '',
`api_version` varchar(8) NOT NULL DEFAULT '1.0.0',
+ `device_id` varchar(255) NOT NULL DEFAULT '1.0.0',
`ip` varchar(15) NOT NULL,
`usage_count` int(10) unsigned NOT NULL,
+ `user_id` int(10) unsigned NOT NULL,
`last_access` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`user_id`,`device_id`,`api_version`),
CONSTRAINT `api_usage_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `RABC_users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
-) ENGINE=InnoDB DEFAULT CHARSET=latin1
+);
+
diff --git a/pbp_web b/pbp_web
new file mode 120000
index 0000000..3acee34
--- /dev/null
+++ b/pbp_web
@@ -0,0 +1 @@
+Dokumenty/Development/chanda/chroot_whezzy/home/finch/PBP/pbp_web
\ No newline at end of file
diff --git a/test b/test
new file mode 100644
index 0000000..05c2b77
--- /dev/null
+++ b/test
@@ -0,0 +1,22 @@
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
+...
diff --git a/view/progress/._add_meal_progress_with_nutrients.php b/view/progress/._add_meal_progress_with_nutrients.php
index 67414a7..d95dddd 100644
Binary files a/view/progress/._add_meal_progress_with_nutrients.php and b/view/progress/._add_meal_progress_with_nutrients.php differ
diff --git a/controller/admin/._messages.php b/controller/admin/._messages.php
index 03c304e..027cfce 100644
Binary files a/controller/admin/._messages.php and b/controller/admin/._messages.php differ
diff --git a/controller/api/api_v1_0_0.php b/controller/api/api_v1_0_0.php
index c6042cd..dee469f 100644
--- a/controller/api/api_v1_0_0.php
+++ b/controller/api/api_v1_0_0.php
@@ -26,6 +26,7 @@ class ApiV1_0_0Controller extends SiteController {
'message_to_coach',
'save_weekplan',
'save_progress_meal',
+ 'generate_meal_suggestion',
'save_measurement',
'get_measurements',
'set_device_id',
@@ -43,22 +44,220 @@ class ApiV1_0_0Controller extends SiteController {
'use_coupon',
'use_credits',
'release_coupon',
- 'release_credits'
+ 'release_credits',
+ 'get_product_info',
+ 'get_recipe_info',
+ 'search_products_meals',
+ 'get_user_most_selected_nutrients',
+ 'get_user_recent_nutrients',
+ 'get_user_favorite_nutrients',
+ 'set_activity_level',
+ 'swap_meal_suggestion_part'
)
)
);
+ var $userDataIsUpdated = false;
+
+ public function __construct() {
+ parent::__construct();
+
+ header('Content-Type: application/json');
+ $_SESSION['login_current_subscription'] = true;
+
+ $oauth = Loader::component('OAuth');
+ $token = $oauth->verifyToken();
+
+ if (!$token) {
+ echo json_encode(array(
+ 'error' => 'no_token',
+ 'error_description' => 'Token incorrect'));
+ die();
+ } else {
+ if (!$this->Auth->isAuth()) {
+ $_GET['grant_type'] = 'access_token';
+ if (!$this->Auth->loginFromOAuth($_GET, $token)) {
+ echo json_encode(array(
+ 'error' => 'no_auth',
+ 'error_description' => 'Not authorized. No authorized user found in session'));
+ die();
+ } else {
+ $this->userDataIsUpdated = true;
+ }
+ }
+ }
+
+ $this->isAjaxCall();
+ }
/*
* *************************************************************************************************************************
* ********** PUBLIC FUNCTIONS (viewable) **********************************************************************************
* *********************************************************************************************************************** */
+ public function swap_meal_suggestion_part() {
+ $data = false;
+
+ if (isset($_REQUEST['day']) && isset($_REQUEST['type']) && isset($_REQUEST['order_n']) && isset($_REQUEST['fk']) && isset($_REQUEST['mealtype_id'])) {
+ $dayN = Filter::int($_REQUEST['day']);
+ $orderN = $_REQUEST['order_n'];
+ $mealtypeId = $_REQUEST['mealtype_id'];
+ $fk = $_REQUEST['fk'];
+ $type = $_REQUEST['type'];
+
+ $allowedTypes = array(
+ 'recipes',
+ 'supplements',
+ 'fruits');
+
+ if (in_array($type, $allowedTypes) && $dayN > 0) {
+ $this->attachModel(array(
+ 'Users',
+ 'Nutrition'));
+
+ $swap = array(
+ 'day_n' => $dayN,
+ 'type' => $type,
+ 'order_n' => $orderN,
+ 'fk' => $fk,
+ 'mealtype_id' => $mealtypeId
+ );
+
+ // Get data
+ $filter = array(
+ 'allergies' => $this->Users->getColumnBy(array(
+ 'user_id' => $this->Auth->user['id']), array(
+ 'fields' => array(
+ 'allergy_id')), 'users_allergies ua')
+ );
+ $budget = $this->Nutrition->getBudget($this->Auth->user['subscription_id'], $this->Auth->user['program'], $this->Nutrition->getSuggestionDayType($swap['day_n']));
+ $selections = $this->Nutrition->getSuggestionSelections($this->Auth->user['program'], $filter, array(
+ $swap['type']));
+
+
+ $swapped = $this->Nutrition->swapSuggestion($this->Auth->user['subscription_id'], $budget, $selections, $swap);
+ if ($swapped) {
+ $suggestion = $this->Nutrition->getMealSuggestions($this->Auth->user['subscription_id'], $swap['day_n'], true);
+ $data = array(
+ 'nutrition_suggestions' => array(
+ 'timestamp' => strtotime($suggestion['created']),
+ 'data' => array(
+ $suggestion)
+ )
+ );
+ } else {
+ $data = array(
+ 'nutrition_suggestions' => array(
+ 'timestamp' => time(),
+ 'data' => false
+ )
+ );
+ }
+ }
+ }
+
+ if (!$data) {
+ $this->set(array(
+ 'ajax' => array(
+ false)));
+ } else {
+ $this->set(array(
+ 'ajax' => $data));
+ }
+ }
+
+ public function generate_meal_suggestion() {
+ $data = false;
+
+ if (isset($_REQUEST['day']) && isset($_REQUEST['meals'])) {
+ $day = Filter::int($_REQUEST['day']);
+ $meals = Filter::int($_REQUEST['meals']);
+
+ if ($meals >= 3 && $meals <= 6 && $day <= 6) {
+ $this->attachModel(array(
+ 'Nutrition',
+ 'Users'));
+
+ if ($day >= 4) {
+ $type = 'training';
+ } else {
+ $type = 'normal';
+ }
+
+ $filter = array(
+ 'allergies' => $this->Users->getColumnBy(array(
+ 'user_id' => $this->Auth->user['id']), array(
+ 'fields' => array(
+ 'allergy_id')), 'users_allergies ua'));
+ $budget = $this->Nutrition->getBudget($this->Auth->user['subscription_id'], $this->Auth->user['program'], $type);
+ $selections = $this->Nutrition->getSuggestionSelections($this->Auth->user['program'], $filter);
+
+ if ($budget && $selections) {
+ $success = $this->Nutrition->generateMealSuggestions($this->Auth->user['subscription_id'], $this->Auth->user['program'], $budget, $selections, $meals, $day, $type);
+ if ($success) {
+ $suggestion = $this->Nutrition->getMealSuggestions($this->Auth->user['subscription_id'], $day, true);
+ if ($suggestion) {
+ $data = array(
+ 'nutrition_suggestions' => array(
+ 'timestamp' => strtotime($suggestion['created']),
+ 'data' => array(
+ $suggestion)
+ )
+ );
+ }
+ } else {
+ $data = array(
+ 'nutrition_suggestions' => array(
+ 'timestamp' => time(),
+ 'data' => false
+ )
+ );
+ }
+ }
+ }
+ }
+
+ if (!$data) {
+ $this->set(array(
+ 'ajax' => array(
+ $data)));
+ } else {
+ $this->set(array(
+ 'ajax' => $data));
+ }
+ }
+
public function get_user_data() {
- $this->Auth->user['program']['start_day'] = $this->Auth->user['program']['start'];
- $ajax = $this->Auth->user;
+ $ajax = $this->getUserDataObject();
+
$this->set(compact('ajax'));
}
+ private function getUserDataObject() {
+ $this->Auth->user['program']['start_day'] = $this->Auth->user['program']['start'];
+ $user = $this->Auth->user;
+
+ $this->attachModel(array(
+ 'Users'));
+ $user['birthdate'] = $this->Users->getOneBy(array(
+ 'user_id' => $this->Auth->user['id']), array(
+ 'fields' => array(
+ 'birthdate')), 'users');
+
+
+ unset($user['level']);
+ unset($user['measurements']);
+ unset($user['subscriptions']);
+ unset($user['roles']);
+ unset($user['forum_notification']);
+ unset($user['need_progress']);
+ unset($user['get_new_subscription']);
+ unset($user['device_id']);
+ unset($user['email']);
+ unset($user['client']);
+
+ return $user;
+ }
+
public function get_user_address() {
$this->attachModel(array(
'Users'));
@@ -200,8 +399,14 @@ class ApiV1_0_0Controller extends SiteController {
'Progress',
'Users',
'Subscriptions'));
+
+ if (!$this->userDataIsUpdated) {
+ $this->Auth->updateUser();
+ }
+
$day = $this->General->getDay($this->Auth->user['subscription_id']);
+
// Is last "sync" or login in the right day?
$last_filled_day = $this->Progress->getLastFilledDay($this->Auth->user['subscription_id'], $day['n']);
if ($last_filled_day < $day['n']) {
@@ -213,7 +418,8 @@ class ApiV1_0_0Controller extends SiteController {
'device_id' => "",
'device_type' => "",
'schedule_id' => 0,
- 'schedule_timestamp' => 0
+ 'schedule_timestamp' => 0,
+ 'api_version' => 1
);
$app_timestamps = array(
"training_exercises" => 0,
@@ -225,6 +431,9 @@ class ApiV1_0_0Controller extends SiteController {
"nutrition_nutrients" => 0,
"nutrition_portions" => 0,
"nutrition_meals_per_daytype" => 0,
+ "nutrition_mealtypes_per_n" => 0,
+ 'nutrition_suggestions' => 0,
+ 'nutrition_caloriebudgets' => 0,
"week_plan" => 0,
"next_week_plan" => 0
);
@@ -292,10 +501,16 @@ class ApiV1_0_0Controller extends SiteController {
}
$handle = 'nutrition_products';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
+ if ($app_state['api_version'] == 1) {
+ $data[$handle] = array(
+ 'timestamp' => $timestamps[$handle],
+ 'data' => $this->Nutrition->getSortedProductsForProgramLegacy($this->Auth->user['program']));
+ } else {
$data[$handle] = array(
'timestamp' => $timestamps[$handle],
'data' => $this->Nutrition->getSortedProductsForProgram($this->Auth->user['program']));
}
+ }
$handle = 'nutrition_allergies';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
$data[$handle] = array(
@@ -307,10 +522,47 @@ class ApiV1_0_0Controller extends SiteController {
// - Update according to timestamped versions OR program (login)
$handle = 'nutrition_recipes';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
+ if ($app_state['api_version'] == 1) {
+ $data[$handle] = array(
+ 'timestamp' => $timestamps[$handle],
+ 'data' => $this->Nutrition->getAllRecipesForProgramLegacy($this->Auth->user['program']));
+ } else {
$data[$handle] = array(
'timestamp' => $timestamps[$handle],
'data' => $this->Nutrition->getAllRecipesForProgram($this->Auth->user['program']));
}
+ }
+
+ // Caloriebudgets?
+ $hasBudgets = false;
+ switch ($this->Auth->user['nutrition_method']) {
+ default:break;
+ case "caloriecount":
+ case "mealsuggestion":
+ $handle = 'nutrition_caloriebudgets';
+ $caloriebudget_timestamp = $this->Nutrition->fetchOne("SELECT UNIX_TIMESTAMP(`created`) FROM `subscriptions_caloriebudgets` WHERE `subscription_id` = " . $this->Auth->user['subscription_id'] . " ORDER BY `created` DESC LIMIT 0,1");
+ if ($caloriebudget_timestamp) {
+ $hasBudgets = true;
+ }
+ if ($hasBudgets && ($caloriebudget_timestamp == 0 || $app_timestamps[$handle] != $caloriebudget_timestamp)) {
+ $budgetNormal = $this->Nutrition->getBudgetBase($this->Auth->user['subscription_id'], $this->Auth->user['program'], 'normal');
+ $budgetTraining = $this->Nutrition->getBudgetBase($this->Auth->user['subscription_id'], $this->Auth->user['program'], 'training');
+ if ($budgetNormal && $budgetTraining) {
+ $data[$handle] = array(
+ 'timestamp' => $caloriebudget_timestamp,
+ 'data' => array(
+ $budgetNormal,
+ $budgetTraining
+ )
+ );
+ }
+ }
+ break;
+ }
+
+ // Meals per day
+ switch ($this->Auth->user['nutrition_method']) {
+ case "hand":
$handle = 'nutrition_nutrients';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
$data[$handle] = array(
@@ -339,12 +591,49 @@ class ApiV1_0_0Controller extends SiteController {
'protein',
'fats')), 'nutrition_mealtypes_portions'));
}
+
$handle = 'nutrition_meals_per_daytype';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
$data[$handle] = array(
'timestamp' => $timestamps[$handle],
'data' => $this->Nutrition->getMealsPerDaytype($this->Auth->user['program']));
}
+ break;
+ case "caloriecount":
+ $handle = "nutrition_mealtypes_per_n";
+ if ($app_timestamps[$handle] != $timestamps[$handle]) {
+ $meals = array(
+ "training" => array(),
+ "normal" => array());
+
+ $meals["normal"][] = $this->Nutrition->getMealtypesForMealsPerDay(3, $this->Auth->user['program'], "normal");
+ $meals["normal"][] = $this->Nutrition->getMealtypesForMealsPerDay(4, $this->Auth->user['program'], "normal");
+ $meals["normal"][] = $this->Nutrition->getMealtypesForMealsPerDay(5, $this->Auth->user['program'], "normal");
+ $meals["normal"][] = $this->Nutrition->getMealtypesForMealsPerDay(6, $this->Auth->user['program'], "normal");
+
+ $meals["training"][] = $this->Nutrition->getMealtypesForMealsPerDay(3, $this->Auth->user['program'], "training");
+ $meals["training"][] = $this->Nutrition->getMealtypesForMealsPerDay(4, $this->Auth->user['program'], "training");
+ $meals["training"][] = $this->Nutrition->getMealtypesForMealsPerDay(5, $this->Auth->user['program'], "training");
+ $meals["training"][] = $this->Nutrition->getMealtypesForMealsPerDay(6, $this->Auth->user['program'], "training");
+
+ $data[$handle] = array(
+ 'timestamp' => $timestamps[$handle],
+ 'data' => $meals);
+ }
+
+ break;
+ case "mealsuggestion":
+ $handle = 'nutrition_suggestions';
+ $suggestion_timestamp = $this->Nutrition->fetchOne("SELECT UNIX_TIMESTAMP(`created`) FROM `subscriptions_meal_suggestions` WHERE `subscription_id` = " . $this->Auth->user['subscription_id'] . " ORDER BY `created` DESC LIMIT 0,1");
+
+ if ($hasBudgets && ($suggestion_timestamp == 0 || $app_timestamps[$handle] != $suggestion_timestamp)) {
+ $data[$handle] = array(
+ 'timestamp' => Filter::int($suggestion_timestamp),
+ 'data' => $this->Nutrition->getAllMealSuggestions($this->Auth->user['subscription_id']));
+ }
+ break;
+ }
+
$handle = 'recovery_supplements';
if ($app_timestamps[$handle] != $timestamps[$handle]) {
$data[$handle] = array(
@@ -432,10 +721,12 @@ class ApiV1_0_0Controller extends SiteController {
$this->Users->update(array(
'device_id' => ''), array(
- 'device_id' => trim($app_state['device_id']), "device_type" => $device_type), 'users_clients');
+ 'device_id' => trim($app_state['device_id']),
+ "device_type" => $device_type), 'users_clients');
$this->Users->update(array(
- 'device_id' => trim($app_state['device_id']), "device_type" => $device_type), array(
+ 'device_id' => trim($app_state['device_id']),
+ "device_type" => $device_type), array(
'user_id' => $this->Auth->user['id']), 'users_clients');
}
@@ -466,6 +757,8 @@ class ApiV1_0_0Controller extends SiteController {
$data['now']['first_measurement'] = (isset($this->Auth->user['measurements']) && $this->Auth->user['measurements']['first']);
$data['now']['program_over'] = $this->Auth->user['program_over'];
+ $data['userdata'] = $this->getUserDataObject();
+
$this->set(array(
'ajax' => $data));
}
@@ -530,6 +823,36 @@ class ApiV1_0_0Controller extends SiteController {
$this->set(compact('ajax'));
}
+ public function get_product_info() {
+ $ajax = false;
+ if (isset($_REQUEST['id'])) {
+ $product_id = Filter::int($_REQUEST['id']);
+ $this->attachModel(array(
+ 'Nutrition'));
+ $data = $this->Nutrition->getProductWithNutrients($product_id, $this->Auth->user['program']);
+ $this->set(array(
+ 'ajax' => $data));
+ } else {
+ $this->set(array(
+ 'ajax' => $ajax));
+ }
+ }
+
+ public function get_recipe_info() {
+ $ajax = false;
+ if (isset($_REQUEST['id'])) {
+ $product_id = Filter::int($_REQUEST['id']);
+ $this->attachModel(array(
+ 'Nutrition'));
+ $data = $this->Nutrition->getRecipe($product_id, $this->Auth->user['program']);
+ $this->set(array(
+ 'ajax' => $data));
+ } else {
+ $this->set(array(
+ 'ajax' => $ajax));
+ }
+ }
+
public function get_weekplan() {
$ajax = false;
@@ -773,6 +1096,8 @@ class ApiV1_0_0Controller extends SiteController {
}
public function save_progress_meal() {
+ // TODO: Combine with save in ProgressController (same functionality)
+
$ajax = false;
if (isset($_REQUEST['text']) && isset($_REQUEST['time']) && isset($_REQUEST['mealtype_id']) && isset($_REQUEST['day'])) {
$this->attachModel(array(
@@ -792,19 +1117,70 @@ class ApiV1_0_0Controller extends SiteController {
$day_n = $day['n'] - 2;
break;
}
+ $day_n = Filter::int($day_n);
if ($day_n < 1) {
$day_n = 1;
}
$time = $_REQUEST['time'];
$save = array(
- 'subscription_id' => Filter::int($this->Auth->user['subscription_id']),
- 'day' => Filter::int($day_n),
+ 'subscription_id' => $this->Auth->user['subscription_id'],
+ 'day' => $day_n,
'time' => $time,
'mealtype_id' => Filter::int($_REQUEST['mealtype_id']),
- 'description' => $_REQUEST['text']
+ 'description' => $_REQUEST['text'],
+ 'has_nutrients' => 0
+ );
+
+ // save nutrients if send
+ if (isset($_REQUEST['nutrients']) && is_array($_REQUEST['nutrients'])) {
+ $nutrients_save = array();
+ $save['has_nutrients'] = 1;
+ foreach ($_REQUEST['nutrients'] as $nutrient) {
+
+ $nutrient_save = array(
+ 'subscription_id' => $this->Auth->user['subscription_id'],
+ 'day' => $day_n,
+ 'time' => $time,
+ 'name' => $nutrient['name'],
+ 'calories' => $nutrient['calories'],
+ 'carbs' => $nutrient['carbs'],
+ 'fats' => $nutrient['fats'],
+ 'protein' => $nutrient['protein'],
+ 'fibers' => $nutrient['fibers']
);
+
+ switch ($nutrient['type']) {
+ case 0:
+ $nutrient_save['fk'] = $nutrient['product_id'];
+ $nutrient_save['variety_id'] = $nutrient['variety_id'];
+ $nutrient_save['type'] = 'product';
+ break;
+ case 1:
+ $nutrient_save['fk'] = $nutrient['recipe_id'];
+ $nutrient_save['variety_id'] = NULL;
+ $nutrient_save['type'] = 'recipe';
+ break;
+ case 2:
+ $nutrient_save['fk'] = NULL;
+ $nutrient_save['variety_id'] = NULL;
+ $nutrient_save['type'] = 'custom';
+ break;
+ }
+ $nutrients_save[] = $nutrient_save;
+ }
+ }
+
$ajax = true;
+
+ $time_str = str_replace(array(
+ ':',
+ ' '), array(
+ '',
+ ''), $time);
+ $savename = $day_n . '_' . ( strlen($time_str) < 4 ? '0' . $time_str : $time_str) . '.jpg';
+ $path = 'data/user_meals/' . $this->Auth->user['subscription_id'] . '/';
+
if (isset($_FILES)) {
Loader::lib(array(
'Image',
@@ -825,13 +1201,6 @@ class ApiV1_0_0Controller extends SiteController {
case "1": // gif
case "2": // jpg
case "3": // png
- $path = 'data/user_meals/' . $this->Auth->user['subscription_id'] . '/';
- $time_str = str_replace(array(
- ':',
- ' '), array(
- '',
- ''), $time);
- $savename = $day_n . '_' . ( strlen($time_str) < 4 ? '0' . $time_str : $time_str) . '.jpg';
$this->Nutrition->saveProgressMealImage($doc, DOCUMENT_ROOT . 'www/' . $path, $savename);
File::deleteFiles(DOCUMENT_ROOT . 'www/tmp/', $file);
@@ -847,8 +1216,34 @@ class ApiV1_0_0Controller extends SiteController {
}
}
}
+ } else {
+ $file_path = DOCUMENT_ROOT . 'www/' . $path . $savename;
+ if (file_exists($file_path)) {
+ @unlink($file_path);
+ }
}
+
$this->Progress->replace($save, 'progress_meals');
+ if (isset($nutrients_save)) {
+ $this->Progress->delete(array(
+ 'subscription_id' => $this->Auth->user['subscription_id'],
+ 'day' => $day_n,
+ 'time' => $time), 'progress_nutrients');
+
+ $this->Progress->insert($nutrients_save, 'progress_nutrients');
+
+ if(isset($_REQUEST['favorite']) && trim($_REQUEST['favorite']) != "") {
+ $favoriteName = ucwords(trim(preg_replace("/[^0-9a-zA-Z ]/", "", $_REQUEST['favorite'])));
+ $this->Progress->replace(
+ array(
+ 'user_id' => $this->Auth->user['id'],
+ 'name' => $favoriteName,
+ 'subscription_id' => $this->Auth->user['subscription_id'],
+ 'day' => $day_n,
+ 'time' => $time
+ ), 'users_favorite_meals');
+ }
+ }
}
if ($ajax) {
@@ -1356,6 +1751,54 @@ class ApiV1_0_0Controller extends SiteController {
$this->set(compact('ajax'));
}
+ public function search_products_meals() {
+ $this->attachModel(array(
+ 'Nutrition'));
+
+ $ajax = false;
+
+ if (isset($_REQUEST['query'])) {
+ $products = $this->Nutrition->searchProductsWithNutrients($_REQUEST['query']);
+ $recipes = $this->Nutrition->searchRecipesWithNutrients($_REQUEST['query']);
+ $ajax = array(
+ 'products' => $products,
+ 'recipes' => $recipes
+ );
+ }
+
+ $this->set(compact('ajax'));
+ }
+
+ public function get_user_favorite_nutrients() {
+ $this->attachModel(array(
+ 'Nutrition'));
+
+ $num_results = isset($_REQUEST['num_results']) && Filter::int($_REQUEST['num_results'], true) !== false ? Filter::int($_REQUEST['num_results'], true) : 20;
+ $ajax = $this->Nutrition->getFavoriteNutrients($this->Auth->user['id'], $num_results);
+
+ $this->set(compact('ajax'));
+ }
+
+ public function get_user_recent_nutrients() {
+ $this->attachModel(array(
+ 'Nutrition'));
+
+ $num_results = isset($_REQUEST['num_results']) && Filter::int($_REQUEST['num_results'], true) !== false ? Filter::int($_REQUEST['num_results'], true) : 20;
+ $ajax = $this->Nutrition->getRecentNutrients($this->Auth->user['subscription_id'], $num_results);
+
+ $this->set(compact('ajax'));
+ }
+
+ public function get_user_most_selected_nutrients() {
+ $this->attachModel(array(
+ 'Nutrition'));
+
+ $num_results = isset($_REQUEST['num_results']) && Filter::int($_REQUEST['num_results'], true) !== false ? Filter::int($_REQUEST['num_results'], true) : 20;
+ $ajax = $this->Nutrition->getMostSelectedNutrients($this->Auth->user['subscription_id'], $num_results);
+
+ $this->set(compact('ajax'));
+ }
+
/*
* *************************************************************************************************************************
* ********** PRIVATE FUNCTIONS ********************************************************************************************
@@ -1424,47 +1867,6 @@ class ApiV1_0_0Controller extends SiteController {
return false;
}
- /*
- public function get_progress() {
- $this->attachModel(array('Progress'));
- $ajax = array();
- $days = array();
-
- if(isset($_REQUEST['days']) && is_array($_REQUEST['days'])) {
- foreach($_REQUEST['days'] as $day) {
- $day = Filter::int($day);
-
- if($day != 0 && !in_array($day, $days)) {
- $days[] = $day;
- }
- }
-
- if(count($days) > 0) {
- $ajax = $this->Progress->getDays($this->Auth->user['subscription_id'], date('Y-m-d', $this->Auth->user['program']['start']), $days);
- }
- }
-
- $this->set(compact('ajax'));
- }
-
- public function get_training_progress() {
- $this->attachModel('Training');
- $ajax = array();
-
- if(isset($_REQUEST['days']) && is_array($_REQUEST['days'])) {
- foreach($_REQUEST['days'] as $day) {
- $day = Filter::int($day);
-
- if($day != 0 && !isset($ajax[$day])) {
- $ajax[$day] = $this->Training->getTrainingFromProgress($this->Auth->user['subscription_id'], $day_n);
- }
- }
- }
-
- $this->set(compact('ajax'));
- }
- */
-
private function nullIsEmpty($str) {
if (strtolower($str) == "null") {
return "";
@@ -1518,7 +1920,7 @@ class ApiV1_0_0Controller extends SiteController {
}
if (isset($daydata['motivation_reason'])) {
- $reason = $this->nullIsEmpty($daydata['training_reason']);
+ $reason = $this->nullIsEmpty($daydata['motivation_reason']);
if ($reason != "") {
$save_reason[] = array(
'type' => 'motivation',
@@ -1530,12 +1932,12 @@ class ApiV1_0_0Controller extends SiteController {
}
if (isset($daydata['lesson_reason'])) {
- $reason = $this->nullIsEmpty($daydata['training_reason']);
+ $reason = $this->nullIsEmpty($daydata['lesson_reason']);
if ($reason != "") {
$save_reason[] = array(
'type' => 'habit',
'day' => $daydata['day'],
- 'subscription_id' => $this->Auth->user['subscriptionF_id'],
+ 'subscription_id' => $this->Auth->user['subscription_id'],
'reason' => $reason
);
}
@@ -1667,10 +2069,99 @@ class ApiV1_0_0Controller extends SiteController {
$array1 = $array2;
}
- /*
- * *************************************************************************************************************************
- * ********** AJAX FUNCTIONS ***********************************************************************************************
- * *********************************************************************************************************************** */
+ public function set_activity_level() {
+ $ajax = false;
+ if (isset($_REQUEST['points'])) {
+ $activityPoints = Filter::int($_REQUEST['points']);
+
+ $this->attachModel(array(
+ 'Subscriptions',
+ 'Users',
+ 'Nutrition'));
+
+ if (isset($_REQUEST['birthdate'])) {
+ $birthdate = $_REQUEST['birthdate'];
+ $birthdateArr = explode('-', $birthdate);
+ if (count($birthdateArr) == 3) {
+ $this->Users->update(array(
+ 'birthdate' => $birthdate), array(
+ 'user_id' => $this->Auth->user['id']), 'users');
+ }
+ }
+
+ $measurement = $this->Subscriptions->getLatestMeasurements($this->Auth->user['subscription_id']);
+ $birthdate = $this->Users->getOneBy(array(
+ 'user_id' => $this->Auth->user['id']), array(
+ 'fields' => array(
+ 'birthdate')), 'users');
+
+ $sizes = array(
+ 'height' => $measurement['height'],
+ 'weight' => $measurement['weight'],
+ 'age' => date_diff(new DateTime(), new DateTime($birthdate))->format('%y')
+ );
+
+ $day = $this->General->getDay($this->Auth->user['subscription_id']);
+ $this->Nutrition->calculateBudget($this->Auth->user['subscription_id'], $this->Auth->user['program'], $sizes, $activityPoints, $day['week'], 'normal');
+ $this->Nutrition->calculateBudget($this->Auth->user['subscription_id'], $this->Auth->user['program'], $sizes, $activityPoints, $day['week'], 'training');
+
+ $data = array();
+
+ // return new caloriebudget
+ $budgetNormal = $this->Nutrition->getBudgetBase($this->Auth->user['subscription_id'], $this->Auth->user['program'], 'normal');
+ $budgetTraining = $this->Nutrition->getBudgetBase($this->Auth->user['subscription_id'], $this->Auth->user['program'], 'training');
+
+ $caloriebudget_timestamp = $this->Nutrition->fetchOne("SELECT UNIX_TIMESTAMP(`created`) FROM `subscriptions_caloriebudgets` WHERE `subscription_id` = " . $this->Auth->user['subscription_id'] . " ORDER BY `created` DESC LIMIT 0,1");
+ if ($budgetNormal && $budgetTraining) {
+ $handle = 'nutrition_caloriebudgets';
+ $data[$handle] = array(
+ 'timestamp' => $caloriebudget_timestamp,
+ 'data' => array(
+ $budgetNormal,
+ $budgetTraining
+ )
+ );
+
+ if ($this->Auth->user['nutrition_method'] == "mealsuggestion") {
+
+ // Regenerate all suggestions
+ $filter = array(
+ 'allergies' => $this->Users->getColumnBy(array(
+ 'user_id' => $this->Auth->user['id']), array(
+ 'fields' => array(
+ 'allergy_id')), 'users_allergies ua')
+ );
+
+ $selections = $this->Nutrition->getSuggestionSelections($this->Auth->user['program'], $filter);
+ if ($selections) {
+ $success = $this->Nutrition->generateAllMealSuggestions($this->Auth->user['subscription_id'], $this->Auth->user['program'], $budgetNormal, $budgetTraining, $selections, 4);
+
+ $handle = 'nutrition_suggestions';
+ if ($success) {
+ $suggestion_timestamp = $this->Nutrition->fetchOne("SELECT UNIX_TIMESTAMP(`created`) FROM `subscriptions_meal_suggestions` WHERE `subscription_id` = " . $this->Auth->user['subscription_id'] . " ORDER BY `created` DESC LIMIT 0,1");
+ $data[$handle] = array(
+ 'timestamp' => $suggestion_timestamp,
+ 'data' => $this->Nutrition->getAllMealSuggestions($this->Auth->user['subscription_id'])
+ );
+ } else {
+ $suggestion_timestamp = 0;
+ $data[$handle] = array(
+ 'timestamp' => $suggestion_timestamp,
+ 'data' => false
+ );
+ }
+ }
+ }
+ }
+
+ if (count($data) > 0) {
+ $ajax = $data;
+ }
+
+ $this->set(compact('ajax'));
+ }
+ }
+
}
?>
\ No newline at end of file
diff --git a/lib/ai/._Apn.class.php b/lib/ai/._Apn.class.php
index 8acc95b..3131da3 100644
Binary files a/lib/ai/._Apn.class.php and b/lib/ai/._Apn.class.php differ
diff --git a/lib/secure_hash/new_secure_hash.class.php b/lib/secure_hash/new_secure_hash.class.php
index 6118068..91b7498 100644
--- a/lib/secure_hash/new_secure_hash.class.php
+++ b/lib/secure_hash/new_secure_hash.class.php
@@ -29,19 +29,19 @@ class new_secure_hash extends secure_hash {
function check($hash_formated, $pass) {
$password_array = explode($this->delimiter, $hash_formated);
- list(,$hashmethod, $salt, $iter, $hash) = $password_array;
- if ($hashmethod == 'blowfish') {
- list(,$hashmethod,,,$m1,$m2,$m3,$hash) = $password_array;
+ list(,$hashing_method, $salt, $iter, $hash) = $password_array;
+ if ($hashing_method == 'blowfish') {
+ list(,$hashing_method,,,$m1,$m2,$m3,$hash) = $password_array;
$lib = new PasswordLib\PasswordLib();
return $lib->verifyPasswordHash($pass, $m1.'$'.$m2.'$'.$m3.'$'.$hash);
}
else {
- $hm = $this->hashmethod;
+ $hm = $this->hashing_method;
$sl = $this->salt_len;
- $this->hashmethod = $hashing_method;
+ $this->hashing_method = $hashing_method;
$this->salt_len = strlen($salt);
$check = parent::check($hash_formated, $pass);
- $this->hashmethod = $hm;
+ $this->hashing_method = $hm;
$this->salt_len = $sl;
return $check;
}
diff --git a/migrations/001-api.sql b/migrations/001-api.sql
index 0beb4ed..1b36d87 100644
--- a/migrations/001-api.sql
+++ b/migrations/001-api.sql
@@ -1,12 +1,11 @@
use pbp;
CREATE TABLE IF NOT EXISTS `api_usage` (
+ `user_id` int(10) unsigned NOT NULL,
+ `device_id` varchar(255) NOT NULL DEFAULT '',
`api_version` varchar(8) NOT NULL DEFAULT '1.0.0',
- `device_id` varchar(255) NOT NULL DEFAULT '1.0.0',
`ip` varchar(15) NOT NULL,
`usage_count` int(10) unsigned NOT NULL,
- `user_id` int(10) unsigned NOT NULL,
`last_access` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`user_id`,`device_id`,`api_version`),
CONSTRAINT `api_usage_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `RABC_users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
-);
-
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
diff --git a/pbp_web b/pbp_web
deleted file mode 120000
index 3acee34..0000000
--- a/pbp_web
+++ /dev/null
@@ -1 +0,0 @@
-Dokumenty/Development/chanda/chroot_whezzy/home/finch/PBP/pbp_web
\ No newline at end of file
diff --git a/test b/test
deleted file mode 100644
index 05c2b77..0000000
--- a/test
+++ /dev/null
@@ -1,22 +0,0 @@
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
-...
diff --git a/view/progress/._add_meal_progress_with_nutrients.php b/view/progress/._add_meal_progress_with_nutrients.php
index d95dddd..67414a7 100644
Binary files a/view/progress/._add_meal_progress_with_nutrients.php and b/view/progress/._add_meal_progress_with_nutrients.php differ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment