/**
  * sends a standard email
  * 
  * @param string $subject
  * @param string $toName
  * @param array $toEmails
  * @param array $emailOptions
  * @param string $fromName
  * @param string $fromEmail
  */
 public function send($subject, $toName, $toEmails = array(), $emailOptions = array(), $fromName = null, $fromEmail = null)
 {
     $logger = Zend_Registry::get('logger');
     $config = vkNgine_Config::getSystemConfig()->mail;
     if ($config->serverType == 'smtp') {
         $tr = new Zend_Mail_Transport_Smtp($config->server, $config->toArray());
     }
     Zend_Mail::setDefaultTransport($tr);
     foreach ($toEmails as $email) {
         $mail = new Zend_Mail();
         if ($emailOptions['type'] == 'html') {
             $mail->setBodyHtml($emailOptions['email']);
         } else {
             $mail->setBodyText($emailOptions['email']);
         }
         if (!$fromName || !$fromEmail) {
             $mail->setFrom($config->noreply, 'GYM Tracker');
         } else {
             $mail->setFrom($fromEmail, $fromName);
         }
         $mail->addTo($email, $toName);
         $mail->setSubject($subject);
         try {
             $mail->send();
         } catch (Zend_Mail_Protocol_Exception $e) {
             $logger->log('MESSAGE_SEND_FAILED', 'Unable to send to ' . $email . ' - ' . $e->getMessage(), 1);
         }
     }
 }
 public function __construct($useCache = null, $cacheType = null, $frontendName = 'Core')
 {
     if (!isset($useCache)) {
         $useCache = false;
     }
     if (!isset($cacheType)) {
         $cacheType = 'file';
     }
     $automaticSerialization = true;
     if ($cacheType == self::FILE) {
         $config = vkNgine_Config::getSystemConfig();
         $cacheDir = $config->cache->dir;
         if (!file_exists($cacheDir)) {
             mkdir($cacheDir);
         }
         $backendName = $cacheType;
         $backendOptions = array('cache_dir' => $cacheDir);
         $frontendOptions = array('caching' => $useCache, 'lifetime' => $config->cache->lifetime, 'automatic_serialization' => $automaticSerialization);
         $this->_cacheObject = Zend_Cache::factory($frontendName, $backendName, $frontendOptions, $backendOptions);
     } elseif ($cacheType == self::MEMCACHED) {
         $backendName = $cacheType;
         $backendOptions = array('servers' => array(array('host' => '127.0.0.1', 'port' => '11211')), 'compression' => true);
         $frontendOptions = array('caching' => $useCache, 'write_control' => true, 'automatic_serialization' => $automaticSerialization, 'ignore_user_abort' => true);
         $this->_cacheObject = Zend_Cache::factory($frontendName, $backendName, $frontendOptions, $backendOptions);
     } else {
         throw new Exception($cacheType . ' - cache type is not supported');
     }
 }
 public function viewAction()
 {
     if ($this->_getParam('assetType') == 'picture') {
         $path = '/images/exercises';
     }
     if ($this->_getParam('type') == 'thumb') {
         $type = '/thumb';
     } elseif ($this->_getParam('type') == 'full') {
         $type = '/full';
     }
     if ($this->_getParam('kind')) {
         switch ($this->_getParam('kind')) {
             case 'glutes, hamstrings, quadriceps':
             case 'glutes':
             case 'hamstrings':
             case 'quadriceps':
                 $kind = '/legs';
                 break;
             case 'abs':
                 $kind = '/abdominals';
                 break;
             case 'back':
                 $kind = '/back';
                 break;
             case 'biceps':
                 $kind = '/biceps';
                 break;
             case 'calves':
                 $kind = '/calves';
                 break;
             case 'chest':
                 $kind = '/chest';
                 break;
             case 'shoulders':
                 $kind = '/shoulders';
                 break;
             case 'back':
                 $kind = '/back';
                 break;
             case 'forearms':
                 $kind = '/forearms';
                 break;
             case 'traps':
                 $kind = '/traps';
                 break;
             case 'triceps':
                 $kind = '/triceps';
                 break;
         }
     }
     $file = '/' . $this->_getParam('file');
     $file = vkNgine_Config::getSystemConfig()->assets->path . $path . $type . $kind . $file;
     $this->_helper->viewRenderer->setNoRender(true);
     $this->view->layout()->disableLayout();
     $image = readfile($file);
     header('Content-Type: image/jpg');
     $modified = new Zend_Date(filemtime($file));
     $this->getResponse()->setHeader('Last-Modified', $modified->toString(Zend_Date::RFC_1123))->setHeader('Content-Type', 'image/jpg')->setHeader('Expires', '', true)->setHeader('Cache-Control', 'public', true)->setHeader('Cache-Control', 'max-age=3800')->setHeader('Pragma', '', true);
     echo $image;
 }
 /**
  * formats a given date with the specific options
  * 
  * @param string $date
  * @param Zend_Date const $format
  * @return string
  */
 public function dateFormat($date, $format)
 {
     if (!empty($date)) {
         $date = new Zend_Date($date, Zend_Date::ISO_8601, vkNgine_Config::getSystemConfig()->language->locale);
         return $date->toString($format);
     }
     return Zend_Registry::get('t')->_('An error occurred during formatting the given date');
 }
 /** 
  * fetch all admin users with pagination
  * 
  * @return Zend_Paginator
  */
 public function fetchAllWithPagination($page, $orderBy = 'userId', $orderBySort = 'ASC')
 {
     $select = $this->select();
     $select->order($orderBy . ' ' . $orderBySort);
     $paginator = Zend_Paginator::factory($select);
     if ($page != 'ALL') {
         $paginator->setItemCountPerPage(vkNgine_Config::getSystemConfig()->pagination->perPage)->setCurrentPageNumber($page);
     } else {
         $paginator->setItemCountPerPage(9999);
     }
     return $paginator;
 }
 public function loginAction()
 {
     if (vkNgine_Auth::isAuthenticated()) {
         header("location:/");
         exit;
     }
     $logger = Zend_Registry::get('logger');
     $form = $this->getLoginForm();
     $request = $this->getRequest();
     $this->view->error = false;
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $info = $form->getValues();
             $user = null;
             if (vkNgine_Public_Auth::attemptLogin($info)) {
                 $user = vkNgine_Auth::revalidate();
             } else {
                 $this->view->error = true;
             }
             $user = vkNgine_Auth::revalidate();
             $logger->log('LOGIN_REQUEST', print_r($info, true), vkNgine_Log::INFO, $user['userId']);
             if ($user != null) {
                 $modelUsers = new Model_Users();
                 $modelTrafficActivity = new vkNgine_Log_Activity();
                 $modelTrafficLogins = new vkNgine_Log_Logins();
                 $modelTrafficActivity->processActivity($user, $request, 'Logged in to Site');
                 $modelTrafficLogins->insertTrafficLogin($user->userId, $user->type);
                 $config = vkNgine_Config::getSystemConfig();
                 Zend_Session::rememberMe($config->settings->login->remember);
                 $modelUsers->update($user['userId'], array('lastLogin' => date('Y-m-d H:i:s')));
                 echo Zend_Json::encode(array('success' => 1, 'icon' => 'success', 'href' => '/'));
                 exit;
             } else {
                 echo Zend_Json::encode(array('title' => $this->t->_('Error Message'), 'message' => $this->t->_('Access denied!'), 'icon' => 'error'));
                 exit;
             }
         } else {
             echo Zend_Json::encode(array('title' => $this->t->_('Error Message'), 'message' => $this->t->_('Access denied!'), 'icon' => 'error'));
             exit;
         }
     }
     $this->view->form = $form;
 }
 public function init()
 {
     $helper = new vkNgine_View_Helper_AdminUrl();
     $this->view->registerHelper($helper, 'adminUrl');
     $helper = new vkNgine_View_Helper_Dateformat();
     $this->view->registerHelper($helper, 'dateFormat');
     $helper = new vkNgine_View_Helper_FormDate();
     $this->view->registerHelper($helper, 'formDate');
     $helper = new vkNgine_View_Helper_Phoneformat();
     $this->view->registerHelper($helper, 'phoneFormat');
     $helper = new vkNgine_View_Helper_Breadcrumb();
     $this->view->registerHelper($helper, 'breadcrumb');
     $helper = new vkNgine_View_Helper_Plural();
     $this->view->registerHelper($helper, 'plural');
     $view = Zend_Registry::get('view');
     $vkNgineVersion = vkNgine_Version::VERSION;
     $appTitle = sprintf(Zend_Registry::get('t')->_('%s Administrator Control Panel'), 'vkNgine' . $vkNgineVersion[0]);
     $this->view->appTitle = $appTitle;
     $view->headTitle($appTitle, Zend_View_Helper_Placeholder_Container_Abstract::SET);
     if (!vkNgine_Auth::isAuthenticated()) {
         $this->_redirect('/admin/auth/login');
         exit;
     }
     $user = vkNgine_Admin_Auth::revalidate();
     if (!$user) {
         $this->_redirect('/admin/auth/login');
         exit;
     }
     Zend_Registry::set('user', $user);
     $this->view->assign('user', $user);
     $this->user = Zend_Registry::get('user');
     $this->config = vkNgine_Config::getSystemConfig();
     $modelTrafficLogins = new vkNgine_Log_Logins();
     $lastLoggedInInfo = $modelTrafficLogins->fetchLastLoggedInInfo($this->user);
     $this->view->assign('lastLoggedInInfo', $lastLoggedInInfo);
     $this->view->action = array('controller' => $this->_request->controller, 'action' => $this->_request->action);
     $acl = new vkNgine_Admin_Acl();
     $this->acl = $acl;
     Zend_Registry::set('acl', $acl);
     $this->view->t = Zend_Registry::get('t');
     $this->t = Zend_Registry::get('t');
     parent::init();
 }
 public function plural($number, $singular, $plural = null)
 {
     $plural = $plural ? $plural : $singular . 's';
     if ($number == 0) {
         return 'No ' . $plural;
     } elseif ($number == 1) {
         if (vkNgine_Config::getSystemConfig()->language->locale != 'en') {
             $singular = str_replace('"s', '', $singular);
             $singular = str_replace('"', '', $singular);
             return Zend_Registry::get('t')->_('One') . ' ' . $singular;
         } else {
             return Zend_Registry::get('t')->_('One') . ' 2' . $singular;
         }
     } else {
         if (vkNgine_Config::getSystemConfig()->language->locale != 'en') {
             $plural = str_replace('"s', '', $plural);
             $plural = str_replace('"', '', $plural);
             return $number . ' ' . $plural;
         } else {
             return $number . ' ' . $plural;
         }
     }
 }
 /**
  * initalize debugging
  */
 protected function _initDebug()
 {
     $config = vkNgine_Config::getSystemConfig();
     if ($config->settings->debug) {
         define('DEBUG', true);
     }
     if (false === defined('DEBUG')) {
         define('DEBUG', false);
     }
     $logger = Zend_Registry::get('logger');
     $writer = new Zend_Log_Writer_Firebug();
     $logger->addWriter($writer);
 }
 public function loginAction()
 {
     if (vkNgine_Auth::isAuthenticated()) {
         $this->_redirect('/admin');
         exit;
     }
     $view = Zend_Registry::get('view');
     $view->headTitle('Administrator Login');
     $loginForm = $this->getAdminLoginForm();
     $recoverForm = $this->getAdminRecoverForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $email = $this->_getParam('email');
         $password = $this->_getParam('password');
         $remember = $this->_getParam('remember');
         $hash = new Zend_Session_Namespace('CsrfError');
         if ($hash->message) {
             echo Zend_Json::encode(array('title' => $this->t->_('Error Message'), 'message' => $this->t->_($hash->message), 'icon' => 'error'));
             exit;
         } else {
             if ($loginForm->isValid($request->getPost())) {
                 if (!empty($email) && !empty($password)) {
                     $info = array('email' => $email, 'password' => $password, 'remember' => $remember);
                     if (vkNgine_Admin_Auth::attemptLogin($info)) {
                         $this->user = vkNgine_Admin_Auth::revalidate();
                         if (isset($info['remember']) and $info['remember']) {
                             $config = vkNgine_Config::getSystemConfig();
                             if (isset($config->settings->login->remember)) {
                                 $rememberMeHowLong = $config->settings->login->remember;
                             } else {
                                 $rememberMeHowLong = 60 * 60 * 24 * 14;
                                 // 14 days
                             }
                             Zend_Session::rememberMe($rememberMeHowLong);
                         } else {
                             Zend_Session::forgetMe();
                         }
                         $logger = Zend_Registry::get('logger');
                         $logger->log('ADMIN_LOGIN_REQUEST', print_r($info, true), vkNgine_Log::INFO, $this->user['userId']);
                         $modelTrafficLogins = new vkNgine_Log_Logins();
                         $modelTrafficLogins->insertTrafficLogin($this->user['userId'], 'ADMIN');
                         $modelTrafficActivity = new vkNgine_Log_Activity();
                         $modelTrafficActivity->processActivity($this->user, $request, 'Logged in to Admin Panel');
                         $modelUsers = new Admin_Model_Users();
                         $modelUsers->update($this->user['userId'], array('lastLogin' => date('Y-m-d H:i:s')));
                         echo Zend_Json::encode(array('success' => 1, 'title' => $this->t->_('Success Message'), 'message' => $this->t->_('Logged in Successfully'), 'icon' => 'success', 'href' => '/admin'));
                         exit;
                     } else {
                         echo Zend_Json::encode(array('title' => $this->t->_('Error Message'), 'message' => $this->t->_('Invalid Login or Password!'), 'icon' => 'error'));
                         exit;
                     }
                 } else {
                     echo Zend_Json::encode(array('title' => $this->t->_('Error Message'), 'message' => $this->t->_('Username or Password is Invalid!'), 'icon' => 'error'));
                     exit;
                 }
             } else {
                 echo Zend_Json::encode(array('title' => $this->t->_('Error Message'), 'message' => $this->t->_('Username or Password is Invalid!'), 'icon' => 'error'));
                 exit;
             }
         }
     }
     $this->view->loginForm = $loginForm;
     $this->view->recoverForm = $recoverForm;
 }
 public function indexAction()
 {
     parent::init();
     parent::ajaxEnabled();
     $form = $this->getAdminSystemSettingsForm();
     $oldConfig = vkNgine_Config::getSystemConfig();
     $oldValues = $oldConfig->toArray();
     $populateData = array();
     $populateData['app_description'] = $oldValues['meta']['appDescription'];
     $populateData['app_keywords'] = $oldValues['meta']['appKeywords'];
     $populateData['language'] = $oldValues['language']['locale'];
     $populateData['timezone'] = $oldValues['phpSettings']['date']['timezone'];
     $populateData['login_remember'] = $oldValues['settings']['login']['remember'];
     $populateData['per_page'] = $oldValues['pagination']['perPage'];
     $populateData['cache_enabled'] = $oldValues['cache']['use'];
     $populateData['cache_type'] = $oldValues['cache']['type'];
     $populateData['cache_dir'] = $oldValues['cache']['dir'];
     $populateData['cache_lifetime'] = $oldValues['cache']['lifetime'];
     $populateData['default_module'] = $oldValues['resources']['frontController']['defaultModule'];
     $populateData['debug_enabled'] = $oldValues['settings']['debug']['enabled'];
     $populateData['ga_enabled'] = $oldValues['settings']['ga']['enabled'];
     $populateData['ga_code'] = $oldValues['settings']['ga']['code'];
     $populateData['form_expiration_time'] = $oldValues['settings']['formexpiretime'];
     $populateData['mail_server'] = $oldValues['mail']['server'];
     $populateData['mail_type'] = $oldValues['mail']['serverType'];
     $populateData['mail_port'] = $oldValues['mail']['port'];
     $populateData['mail_username'] = $oldValues['mail']['username'];
     $populateData['mail_noreply'] = $oldValues['mail']['noreply'];
     $populateData['mail_password'] = $oldValues['mail']['password'];
     $populateData['live_db_host'] = vkNgine_Config::getConfigByEnvironment('production')->resources->db->params->host;
     $populateData['live_db_user'] = vkNgine_Config::getConfigByEnvironment('production')->resources->db->params->username;
     $populateData['live_db_pass'] = vkNgine_Config::getConfigByEnvironment('production')->resources->db->params->password;
     $populateData['live_dbname'] = vkNgine_Config::getConfigByEnvironment('production')->resources->db->params->dbname;
     $populateData['dev_db_host'] = vkNgine_Config::getConfigByEnvironment('development')->resources->db->params->host;
     $populateData['dev_db_user'] = vkNgine_Config::getConfigByEnvironment('development')->resources->db->params->username;
     $populateData['dev_db_pass'] = vkNgine_Config::getConfigByEnvironment('development')->resources->db->params->password;
     $populateData['dev_dbname'] = vkNgine_Config::getConfigByEnvironment('development')->resources->db->params->dbname;
     $form->populate($populateData);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = $request->getPost();
         if ($form->isValid($post)) {
             $values = $form->getValues();
             $realValues = array();
             foreach ($values as $formName => $field) {
                 $realValues = $field;
             }
             $oldValues = self::array_htmlspecialchars($oldValues);
             $settings = array("global" => array("autoloaderNamespaces" => array("vkNgine" => $oldValues['autoloaderNamespaces']['vkNgine'], "Thumbnail" => $oldValues['autoloaderNamespaces']['Thumbnail'], "Calendar" => $oldValues['autoloaderNamespaces']['Calendar'], "zfdebug" => $oldValues['autoloaderNamespaces']['zfdebug']), "bootstrap" => array("path" => $oldValues['bootstrap']['path'], "class" => $oldValues['bootstrap']['class']), "cache" => array("use" => $realValues['Cache_Settings']['cache_enabled'], "type" => $realValues['Cache_Settings']['cache_type'], "dir" => $realValues['Cache_Settings']['cache_dir'], "lifetime" => $realValues['Cache_Settings']['cache_lifetime']), "assets" => array("path" => $oldValues['assets']['path']), "language" => array("locale" => $realValues['Language_Settings']['language'], "file" => array("en" => array("name" => $oldValues['language']['file']['en']['name'], "master" => $oldValues['language']['file']['en']['master'], "app" => $oldValues['language']['file']['en']['app']), "tr" => array("name" => $oldValues['language']['file']['tr']['name'], "master" => $oldValues['language']['file']['tr']['master'], "app" => $oldValues['language']['file']['tr']['app']))), "phpSettings" => array("date" => array("timezone" => $realValues['Date_and_Time_Settings']['timezone'])), "mail" => array("serverType" => $realValues['Email_Settings']['mail_type'], "server" => $realValues['Email_Settings']['mail_server'], "port" => $realValues['Email_Settings']['mail_port'], "username" => $realValues['Email_Settings']['mail_username'], "auth" => "login", "noreply" => $realValues['Email_Settings']['mail_noreply'], "password" => $realValues['Email_Settings']['mail_password']), "settings" => array("ga" => array("enabled" => $realValues['Google_Analytics_Settings']['ga_enabled'], "code" => $realValues['Google_Analytics_Settings']['ga_code']), "formexpiretime" => $realValues['General_Settings']['form_expiration_time'], "login" => array("remember" => $realValues['General_Settings']['login_remember']), "debug" => $realValues['General_Settings']['debug_enabled']), "meta" => array("appDescription" => $realValues['General_Settings']['app_description'], "appKeywords" => $realValues['General_Settings']['app_keywords']), "master" => array("user" => 1), "pagination" => array("perPage" => $realValues['General_Settings']['per_page']), "resources" => array("modules" => $realValues['General_Settings']['default_module'], "locale" => $realValues['Language_Settings']['language'], "frontController" => array("defaultModule" => $oldValues['resources']['frontController']['defaultModule'], "controllerDirectory" => $oldValues['resources']['frontController']['controllerDirectory'], "moduleDirectory" => $oldValues['resources']['frontController']['moduleDirectory']), "view" => array("helperPath" => $oldValues['resources']['view']['helperPath']), "layout" => array("layoutPath" => $oldValues['resources']['layout']['layoutPath']), "locale" => array("default" => $oldValues['resources']['locale']['default']))));
             $production = array("phpSettings" => array("display_startup_errors" => 0, "display_errors" => 0), "resources" => array("db" => array("adapter" => 'pdo_mysql', "params" => array("host" => $realValues['Application_Environment_Settings_for_Production']['live_db_host'], "username" => $realValues['Application_Environment_Settings_for_Production']['live_db_user'], "password" => $realValues['Application_Environment_Settings_for_Production']['live_db_pass'], "dbname" => $realValues['Application_Environment_Settings_for_Production']['live_dbname']))));
             $development = array("phpSettings" => array("display_startup_errors" => 1, "display_errors" => 1), "settings" => array("debug" => $realValues['General_Settings']['debug_enabled']), "resources" => array("frontController" => array("disableOutputBuffering" => 1, "params" => array("displayExceptions" => 1)), "db" => array("adapter" => 'pdo_mysql', "params" => array("host" => $realValues['Application_Environment_Settings_for_Development']['dev_db_host'], "username" => $realValues['Application_Environment_Settings_for_Development']['dev_db_user'], "password" => $realValues['Application_Environment_Settings_for_Development']['dev_db_pass'], "dbname" => $realValues['Application_Environment_Settings_for_Development']['dev_dbname'], "unix_socket" => '/usr/local/zend/mysql/tmp/mysql.sock'))));
             $config = new Zend_Config($settings, true);
             $config->production = $production;
             $config->development = $development;
             $config->setExtend('production', 'global');
             $config->setExtend('development', 'production');
             $writer = new Zend_Config_Writer_Xml(array("config" => $config, "filename" => APPLICATION_PATH . '/configs/config.xml'));
             $writer->write();
             echo Zend_Json::encode(array('success' => 1, 'title' => $this->t->_('Success Message'), 'message' => $this->t->_('System Settings were updated'), 'icon' => 'success'));
             exit;
         } else {
             echo Zend_Json::encode(array('title' => $this->t->_('Error Message'), 'message' => $this->t->_('Please fill out all required fields'), 'icon' => 'error'));
             exit;
         }
     }
     $this->view->form = $form;
 }
 public function deleteAction()
 {
     $modelUsers = new Model_Users();
     $modelAdminUsers = new Admin_Model_Users();
     $userId = $this->_getParam('userId');
     if (vkNgine_Config::getSystemConfig()->master->user == $userId) {
         return new vkNgine_Exception('This user can\'t be deleted');
     }
     $userInfo = $modelUsers->fetch($userId);
     $modelUsers->delete($userId);
     $modelAdminUsers->delete($userId);
     echo Zend_Json::encode(array('success' => 1, 'itemId' => $userId, 'rowId' => 'user-', 'title' => $this->t->_('Success Message'), 'message' => sprintf($this->t->_('%s was successfully deleted'), $userInfo->getFullName()), 'icon' => 'success'));
     exit;
 }
<?php

/**
 * Initializes the app
 * Include below code to every cron job
 * This file is intended to run on the shell
 * Include path is set for a Zend Framework and library folders
 */
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../app'));
set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'), realpath('/usr/local/zend/share/ZendFramework/library/'), get_include_path())));
chdir(APPLICATION_PATH);
include 'env.php';
require_once 'Zend/Application.php';
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/config.xml');
$application->bootstrap('config')->bootstrap('db')->bootstrap('cache')->bootstrap('logger')->bootstrap('autoload');
$config = vkNgine_Config::getSystemConfig();
$logger = Zend_Registry::get('logger');