diff --git a/README.md b/README.md index 73c157b..387a664 100644 --- a/README.md +++ b/README.md @@ -12,39 +12,39 @@ Watch this [tutorial](https://youtu.be/lkE0ZiSWufg) to see how. + *Company*: [Joomla Component Builder](https://www.joomlacomponentbuilder.com/) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Members Manager](https://www.joomlacomponentbuilder.com/) -+ *First Build*: 6th September, 2015 -+ *Last Build*: 26th September, 2018 ++ *First Build*: 6th July, 2018 ++ *Last Build*: 27th December, 2018 + *Version*: 2.0.x + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html ## Build Time -**90 Hours** or **11 Eight Hour Days** (actual time the author saved - +**112 Hours** or **14 Eight Hour Days** (actual time the author saved - due to [Automated Component Builder](http://joomlacomponentbuilder.com)) > (if creating a folder and file took **5 seconds** and writing one line of code took **10 seconds**, > never making one mistake or taking any coffee break.) -+ *Line count*: **32300** -+ *File count*: **206** -+ *Folder count*: **59** ++ *Line count*: **40016** ++ *File count*: **232** ++ *Folder count*: **61** -**60 Hours** or **8 Eight Hour Days** (the actual time the author spent) +**73 Hours** or **9 Eight Hour Days** (the actual time the author spent) > (with the following break down: -> **debugging @23hours** = codingtime / 4; -> **planning @13hours** = codingtime / 7; -> **mapping @9hours** = codingtime / 10; -> **office @15hours** = codingtime / 6;) +> **debugging @28hours** = codingtime / 4; +> **planning @16hours** = codingtime / 7; +> **mapping @11hours** = codingtime / 10; +> **office @19hours** = codingtime / 6;) -**150 Hours** or **19 Eight Hour Days** +**185 Hours** or **23 Eight Hour Days** (a total of the realistic time frame for this project) > (if creating a folder and file took **5 seconds** and writing one line of code took **10 seconds**, > with the normal everyday realities at the office, that includes the component planning, mapping & debugging.) -Project duration: **3.8 weeks** or **0.8 months** +Project duration: **4.6 weeks** or **1 months** > This **component** was build with a Joomla [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/README.txt b/admin/README.txt index 73c157b..387a664 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -12,39 +12,39 @@ Watch this [tutorial](https://youtu.be/lkE0ZiSWufg) to see how. + *Company*: [Joomla Component Builder](https://www.joomlacomponentbuilder.com/) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Members Manager](https://www.joomlacomponentbuilder.com/) -+ *First Build*: 6th September, 2015 -+ *Last Build*: 26th September, 2018 ++ *First Build*: 6th July, 2018 ++ *Last Build*: 27th December, 2018 + *Version*: 2.0.x + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html ## Build Time -**90 Hours** or **11 Eight Hour Days** (actual time the author saved - +**112 Hours** or **14 Eight Hour Days** (actual time the author saved - due to [Automated Component Builder](http://joomlacomponentbuilder.com)) > (if creating a folder and file took **5 seconds** and writing one line of code took **10 seconds**, > never making one mistake or taking any coffee break.) -+ *Line count*: **32300** -+ *File count*: **206** -+ *Folder count*: **59** ++ *Line count*: **40016** ++ *File count*: **232** ++ *Folder count*: **61** -**60 Hours** or **8 Eight Hour Days** (the actual time the author spent) +**73 Hours** or **9 Eight Hour Days** (the actual time the author spent) > (with the following break down: -> **debugging @23hours** = codingtime / 4; -> **planning @13hours** = codingtime / 7; -> **mapping @9hours** = codingtime / 10; -> **office @15hours** = codingtime / 6;) +> **debugging @28hours** = codingtime / 4; +> **planning @16hours** = codingtime / 7; +> **mapping @11hours** = codingtime / 10; +> **office @19hours** = codingtime / 6;) -**150 Hours** or **19 Eight Hour Days** +**185 Hours** or **23 Eight Hour Days** (a total of the realistic time frame for this project) > (if creating a folder and file took **5 seconds** and writing one line of code took **10 seconds**, > with the normal everyday realities at the office, that includes the component planning, mapping & debugging.) -Project duration: **3.8 weeks** or **0.8 months** +Project duration: **4.6 weeks** or **1 months** > This **component** was build with a Joomla [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/access.xml b/admin/access.xml index 9dafbcc..a21ca14 100644 --- a/admin/access.xml +++ b/admin/access.xml @@ -13,6 +13,7 @@ + @@ -22,6 +23,7 @@ + @@ -48,6 +50,7 @@ + @@ -66,17 +69,24 @@ + + + + + + +
@@ -134,6 +144,26 @@ + + + + + + +
+
+ + + + + + +
+
+ + + +
\ No newline at end of file diff --git a/admin/assets/css/admin.css b/admin/assets/css/admin.css index 0ec57f5..a2632f7 100644 --- a/admin/assets/css/admin.css +++ b/admin/assets/css/admin.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/assets/css/member.css b/admin/assets/css/member.css index 58d7189..095d0de 100644 --- a/admin/assets/css/member.css +++ b/admin/assets/css/member.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/assets/css/members.css b/admin/assets/css/members.css index 026520f..3a84864 100644 --- a/admin/assets/css/members.css +++ b/admin/assets/css/members.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/assets/css/type.css b/admin/assets/css/type.css index 026520f..3a84864 100644 --- a/admin/assets/css/type.css +++ b/admin/assets/css/type.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/assets/css/types.css b/admin/assets/css/types.css index 026520f..3a84864 100644 --- a/admin/assets/css/types.css +++ b/admin/assets/css/types.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/assets/js/admin.js b/admin/assets/js/admin.js index f6daf95..16c13ac 100644 --- a/admin/assets/js/admin.js +++ b/admin/assets/js/admin.js @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/config.xml b/admin/config.xml index 2f645ae..acb10b3 100644 --- a/admin/config.xml +++ b/admin/config.xml @@ -46,6 +46,24 @@ default="10" /> + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/controllers/ajax.json.php b/admin/controllers/ajax.json.php index 5836290..1c4ec74 100644 --- a/admin/controllers/ajax.json.php +++ b/admin/controllers/ajax.json.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -27,9 +27,11 @@ class MembersmanagerControllerAjax extends JControllerLegacy // load the tasks $this->registerTask('checkUnique', 'ajax'); $this->registerTask('getPlaceHolders', 'ajax'); + $this->registerTask('getAnyPlaceHolders', 'ajax'); $this->registerTask('uploadfile', 'ajax'); $this->registerTask('removeFile', 'ajax'); - $this->registerTask('getUserDetails', 'ajax'); + $this->registerTask('getUserDetails', 'ajax'); + $this->registerTask('getChartImageLink', 'ajax'); } public function ajax() @@ -121,6 +123,44 @@ class MembersmanagerControllerAjax extends JControllerLegacy } } break; + case 'getAnyPlaceHolders': + try + { + $returnRaw = $jinput->get('raw', false, 'BOOLEAN'); + $getTypeValue = $jinput->get('getType', NULL, 'WORD'); + if($getTypeValue && $user->id != 0) + { + $result = $this->getModel('ajax')->getAnyPlaceHolders($getTypeValue); + } + else + { + $result = false; + } + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback . "(".json_encode($result).");"; + } + elseif($returnRaw) + { + echo json_encode($result); + } + else + { + echo "(".json_encode($result).");"; + } + } + catch(Exception $e) + { + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback."(".json_encode($e).");"; + } + else + { + echo "(".json_encode($e).");"; + } + } + break; case 'uploadfile': try { @@ -238,6 +278,44 @@ class MembersmanagerControllerAjax extends JControllerLegacy echo "(".json_encode($e).");"; } } + break; + case 'getChartImageLink': + try + { + $returnRaw = $jinput->get('raw', false, 'BOOLEAN'); + $imageValue = $jinput->get('image', NULL, 'STRING'); + if($imageValue && $user->id != 0) + { + $result = $this->getModel('ajax')->getChartImageLink($imageValue); + } + else + { + $result = false; + } + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback . "(".json_encode($result).");"; + } + elseif($returnRaw) + { + echo json_encode($result); + } + else + { + echo "(".json_encode($result).");"; + } + } + catch(Exception $e) + { + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback."(".json_encode($e).");"; + } + else + { + echo "(".json_encode($e).");"; + } + } break; } } diff --git a/admin/controllers/import.php b/admin/controllers/import.php index b3b31ee..d971fdf 100644 --- a/admin/controllers/import.php +++ b/admin/controllers/import.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/controllers/member.php b/admin/controllers/member.php index 5db7464..75aad2f 100644 --- a/admin/controllers/member.php +++ b/admin/controllers/member.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -316,7 +316,17 @@ class MembersmanagerControllerMember extends JControllerForm protected function postSaveHook(JModelLegacy $model, $validData = array()) { // safe all dynamic values (that has been posted) - MembersmanagerHelper::saveDynamicValues($validData, 'member'); + if (isset($validData['id'])) + { + MembersmanagerHelper::saveDynamicValues($validData, 'member'); + // always sync the type with the type_map + if (isset($validData['type'])) + { + MembersmanagerHelper::updateTypes($validData['id'], $validData['type']); + } + // safe all set relationships + MembersmanagerHelper::saveRelationships($validData); + } return; } diff --git a/admin/controllers/members.php b/admin/controllers/members.php index ab39867..7904b66 100644 --- a/admin/controllers/members.php +++ b/admin/controllers/members.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/controllers/type.php b/admin/controllers/type.php index 5e47941..35cd345 100644 --- a/admin/controllers/type.php +++ b/admin/controllers/type.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/controllers/types.php b/admin/controllers/types.php index 7a2f7f6..542efe2 100644 --- a/admin/controllers/types.php +++ b/admin/controllers/types.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/helpers/headercheck.php b/admin/helpers/headercheck.php index 4c1d712..b380a0d 100644 --- a/admin/helpers/headercheck.php +++ b/admin/helpers/headercheck.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/helpers/html/batch_.php b/admin/helpers/html/batch_.php index 97a7807..4da9653 100644 --- a/admin/helpers/html/batch_.php +++ b/admin/helpers/html/batch_.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/helpers/membersmanager.php b/admin/helpers/membersmanager.php index 3b3ec8c..fce0fe8 100644 --- a/admin/helpers/membersmanager.php +++ b/admin/helpers/membersmanager.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -33,57 +33,19 @@ abstract class MembersmanagerHelper protected static $params; /** - * Get placeholders - * - * @param string $type The type of placeholders to return - * - * @return array - * - */ - public static function getPlaceHolders($type) - { - if ('document' === $type) - { - // get company placeholders - if (($company = self::getCompanyDetails('placeholder')) !== false && self::checkArray($company)) - { - // just remove the footer and header placeholders - unset($company['[company_doc_header]']); - unset($company['[company_doc_footer]']); - $placeholders = array_keys($company); - return $placeholders; - } - } - return false; - } + * the button names + **/ + protected static $buttonNames = array(); /** - * Add Join Tables based on filter - * - * @param object $query The database query object - * @param string $filter The target area that made the request - * - * @return array - * - */ - protected static function joinMemberDetails(&$query, $filter = 'none', $db = null) - { - // check if we have the DB object - if (!self::checkObject($db)) - { - // get the database object - $db = JFactory::getDBO(); - } - if ('none' === $filter) - { - // From the users table. - $query->join('LEFT', $db->quoteName('#__users', 'u') . ' ON (' . $db->quoteName('a.user') . ' = ' . $db->quoteName('u.id') . ')'); - // From the membersmanager_member table. - $query->join('LEFT', $db->quoteName('#__membersmanager_member', 'm') . ' ON (' . $db->quoteName('a.main_member') . ' = ' . $db->quoteName('m.id') . ')'); - // From the membersmanager_type table. - $query->join('LEFT', $db->quoteName('#__membersmanager_type', 't') . ' ON (' . $db->quoteName('a.type') . ' = ' . $db->quoteName('t.id') . ')'); - } - } + * the opener + **/ + protected static $opener; + + /** + * the return here path + **/ + protected static $return_here; /** * Get selection based on type @@ -98,16 +60,47 @@ abstract class MembersmanagerHelper */ protected static function getSelection($table = 'member', $method = 'placeholder', $filter = 'none', $db = null) { + // get the global settings + if (!self::checkObject(self::$params)) + { + self::$params = JComponentHelper::getParams('com_membersmanager'); + } // prep for placeholders $f = ''; $b = ''; if ('placeholder' === $method) { - $f = '[member_'; + // get the placeholder prefix + $prefix = self::$params->get('placeholder_prefix', 'membersmanager'); + $f = '[' . $prefix . '_'; $b = ']'; } + // get charts + if ('chart' !== $filter && 'field' !== $filter && method_exists(__CLASS__, 'getAnyAvailableCharts') && method_exists(__CLASS__, 'getAllComponents')) + { + if (($components = self::getAllComponents(null, array('Assessment'))) !== false && self::checkArray($components)) + { + // Chart Target Types + $targets = array(2,3); + // load per component + foreach ($targets as $target) + { + foreach ($components as $component) + { + if (($data = self::getAnyAvailableCharts(null, $target, $component->element)) !== false && self::checkArray($data)) + { + $com = str_replace('com_', '', $component->element); + foreach ($data as $key => $chartData) + { + $charts[$key . '\^/' . $component->element . '\^/' . $target] = $com . '_' . $key; + } + } + } + } + } + } // only get what we need - if ('none' === $filter) + if ('email' === $filter || 'report' === $filter) { // check if we have the DB object if (!self::checkObject($db)) @@ -127,27 +120,505 @@ abstract class MembersmanagerHelper // prep the columns $columns = array_keys($columns); } - // convert the columns for query selection - $selection = array(); - foreach ($columns as $column) + // check if we have columns + if (isset($columns) && self::checkArray($columns)) { - $selection['a.' . $column] = $f . $column . $b; + // convert the columns for query selection + $selection = array(); + foreach ($columns as $column) + { + $selection['a.' . $column] = $f . $column . $b; + // we must add the params + if ('profile' !== $filter && 'field' !== $filter) + { + // set the label for these fields + $selection['setLabel->' . $column] = $f . 'label_' . $column . $b; + } + } + // needed values + if ('member' === $table) + { + // set names and emails + $selection['setMemberName:id|user|name|surname'] = $f . 'name' . $b; + $selection['setMemberEmail:id|user|email'] = $f . 'email' . $b; + $selection['setMemberName:created_by|user'] = $f . 'created_name' . $b; + $selection['setMemberEmail:created_by|user'] = $f . 'created_email' . $b; + $selection['setMemberName:modified_by|user'] = $f . 'modified_name' . $b; + $selection['setMemberEmail:modified_by|user'] = $f . 'modified_email' . $b; + // get name and email + $selection['getMemberName:main_member'] = $f . 'main_name' . $b; + $selection['getMemberEmail:main_member'] = $f . 'main_email' . $b; + // set fancy dates + $selection['fancyDate:created'] = $f . 'created' . $b; + $selection['fancyDate:modified'] = $f . 'modified' . $b; + // set profile image + $selection['setImageLink:profile_image|name'] = $f . 'profile_image_url' . $b; + $selection['setImageHTML:profile_image_url|name'] = $f . 'profile_image_html' . $b; + // set profile + $selection['setProfileLink:id|token'] = $f . 'profile_link_url' . $b; + // set the return value + self::$return_here = urlencode(base64_encode((string) JUri::getInstance())); + // set edit link + $selection['setMemberEditURL:id|created_by'] = $f . 'edit_url' . $b; + // Get the medium encryption. + $mediumkey = MembersmanagerHelper::getCryptKey('medium'); + if ($mediumkey) + { + // Get the encryption object. + self::$opener = new FOFEncryptAes($mediumkey); + } + } + // add the chart div and JS code (only if filter is not chart) + if ('chart' !== $filter && 'field' !== $filter && isset($charts) && self::checkArray($charts)) + { + foreach ($charts as $chart => $value) + { + // make sure the chart name is save + $selection['setMultiChart->' . $chart] = $f . $value . $b; + } + } + return $selection; } - // add joined values if needed (based on filter) - if ('member' === $table && 'none' === $filter) - { - $selection['u.name'] = $f . 'user_name' . $b; - $selection['u.email'] = $f . 'user_email' . $b; - $selection['t.name'] = $f . 'type_name' . $b; - $selection['m.user'] = $f . 'main_user' . $b; - $selection['m.name'] = $f . 'main_name' . $b; - $selection['m.email'] = $f . 'main_email' . $b; - } - return $selection; + return false; } /** - * Get a user Access Types + * set image HTML + **/ + protected static function setImageHTML($object) + { + return '' . $object->get('name', JText::_('COM_MEMBERSMANAGER_MEMBER')) . ' ' . JText::_('COM_MEMBERSMANAGER_IMAGE') . ''; + } + + /** + * set image link + **/ + protected static function setImageLink($item) + { + if (self::checkObject(self::$opener) && ($image = $item->get('profile_image', false)) !== false && !is_numeric($image) && $image === base64_encode(base64_decode($image, true))) + { + // now unlock + $item->set('profile_image', rtrim(self::$opener->decryptString($image), "\0")); + } + // get link + return self::getImageLink($item, 'profile_image', 'name', null, false); + } + + /** + * set member edit url + **/ + protected static function setMemberEditURL($item) + { + if (($url = self::getEditURL($item, 'member', 'members', '&return=' . self::$return_here)) !== false) + { + return $url; + } + return ''; + } + + /** + * set profile link + **/ + protected static function setProfileLink($object) + { + return JRoute::_('index.php?option=com_membersmanager&view=profile&id='. $object->get('id') . ':' . $object->get('token') . '&return=' . self::$return_here); + } + + /** + * set member name + **/ + protected static function setMemberName($object) + { + // check if this is a created by or modified by + if (($user = $object->get('created_by', false)) !== false || ($user = $object->get('modified_by', false)) !== false ) + { + $object->set('user', $user); + } + return self::getMemberName($object->get('id', null), $object->get('user', null), $object->get('name', null), $object->get('surname', null)); + } + + /** + * set member email + **/ + protected static function setMemberEmail($object) + { + // check if this is a created by or modified by + if (($user = $object->get('created_by', false)) !== false || ($user = $object->get('modified_by', false)) !== false ) + { + $object->set('user', $user); + } + return self::getMemberEmail($object->get('id', null), $object->get('user', null), $object->get('email', null)); + } + + /** + * set the session defaults if not set + **/ + protected static function setSessionDefaults() + { + // noting for now + return true; + } + + /** + * get button name + **/ + public static function getButtonName($type, $default) + { + if (!isset(self::$buttonNames[$type])) + { + // get the global settings + if (!self::checkObject(self::$params)) + { + self::$params = JComponentHelper::getParams('com_membersmanager'); + } + // get the button name + self::$buttonNames[$type] = self::$params->get('button_'. $type . '_name', $default); + } + return self::$buttonNames[$type]; + } + + /** + * check if the communication component is set (and get key value) + **/ + public static function communicate($key = null, $default = false, $return = null) + { + if (JComponentHelper::isInstalled('com_communicate') && JComponentHelper::isEnabled('com_communicate')) + { + // check if looking for create_url + if ($key && 'create_url' === $key) + { + $_return = urlencode(base64_encode((string) JUri::getInstance())); + if ($return) + { + return self::getCreateURL('message', 'message', $return . '&return=' . $_return, 'com_communicate'); + } + return self::getCreateURL('message', 'message', '&return=' . $_return, 'com_communicate'); + } + // get the global settings of com_communicate (singleton) + $params = JComponentHelper::getParams('com_communicate'); + // return the key value + if ($key) + { + return $params->get($key, $default); + } + return $params; + } + return $default; + } + + /** + * remove all groups that are part of target groups in the member types + **/ + public static function removeMemberGroups(&$groups) + { + if (self::checkArray($groups)) + { + // get database object + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + $query->select(array('a.id')); + $query->from('#__membersmanager_type AS a'); + $db->setQuery($query); + $db->execute(); + // get all types + $types = $db->loadColumn(); + // now get all target groups + $groups_target = self::getMemberGroupsByType($types, 'groups_target'); + // now update the groups + $groups = array_diff($groups, $groups_target); + } + } + + /** + * Get any placeholders + * + * @param string $component The component placeholders to return + * @param string $type The type of placeholders to return + * @param bool $addCompany The switch to add the company + * + * @return array + * + */ + public static function getAnyPlaceHolders($_component, $type = 'report', $addCompany = false) + { + // check if we are in the correct class + if ('com_membersmanager' !== $_component) + { + // check if the class and method exist + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getPlaceHolders')) + { + return $helperClass::getPlaceHolders($type, $addCompany); + } + } + // check if the class and method exist + elseif (method_exists(__CLASS__, 'getPlaceHolders')) + { + return self::getPlaceHolders($type, $addCompany, 'member'); + } + return false; + } + + + /** + * Get placeholders + * + * @param string $type The type of placeholders to return + * @param bool $addCompany The switch to add the company + * @param string $table The table being targeted + * + * @return array + * + */ + public static function getPlaceHolders($type = 'report', $addCompany = false, $table = 'form') + { + // start loading the placeholders + $placeholders = array(); + if (method_exists(__CLASS__, 'getSelection')) + { + // get form placeholders + if (('report' === $type || 'chart' === $type) && ($form = self::getSelection($table, 'placeholder', $type)) !== false && self::checkArray($form)) + { + // always remove params, since it should never be used in placeholders + unset($form['a.params']); + // be sure to sort the array + sort($form); + // and remove duplicates + $form = array_unique(array_values($form)); + // check if company should be added + if ($addCompany) + { + $placeholders[] = $form; + } + else + { + return $form; + } + } + } + // get company placeholders + if (('document' === $type || $addCompany) && method_exists(__CLASS__, 'getAnyCompanyDetails') && ($company = self::getAnyCompanyDetails('com_membersmanager', 'placeholder')) !== false && self::checkArray($company)) + { + if ('document' === $type) + { + // just remove the footer and header placeholders + unset($company['[company_doc_header]']); + unset($company['[company_doc_footer]']); + } + $placeholders[] = array_keys($company); + } + // check that we have placeholders + if (self::checkArray($placeholders)) + { + return self::mergeArrays($placeholders); + } + return false; + } + + + /** + * The Type Members Memory + * + * @var array + */ + protected static $typeMembers = array(); + + /** + * get members by type + * + * @param int/array $id The Type ID + * @param object $db Database object + * + * @return array of member IDs + * + */ + public static function getMembersByType(&$id, $db) + { + // if the id is an array + if (self::checkArray($id)) + { + $members = array(); + foreach ($id as $_id) + { + if (($_members = self::getMembersByType($_id, $db)) !== false) + { + $members[] = $_members; + } + } + return self::mergeArrays($members); + } + // check if we already have the members set by type + if (!self::checkArray(self::$typeMembers) || !isset(self::$typeMembers[$id]) || !self::checkArray(self::$typeMembers[$id])) + { + // check that we have the database object + if (!$db) + { + // get DB + $db = JFactory::getDBO(); + } + // get types that allow relationships + $query = $db->getQuery(true); + $query->select('a.member'); + $query->from('#__membersmanager_type_map AS a'); + $query->where('a.type = ' . (int) $id); + $query->where('a.member > 0'); + $db->setQuery($query); + $db->execute(); + // only continue if we have member types + if (($members = $db->loadColumn()) !== false && self::checkArray($members)) + { + self::$typeMembers[$id] = $members; + } + } + // check if we found member types + if (self::checkArray(self::$typeMembers) && isset(self::$typeMembers[$id]) && self::checkArray(self::$typeMembers[$id])) + { + return self::$typeMembers[$id]; + } + return false; + } + + + /** + * get the relationships by types + * + * @param object $member_types Member Types + * @param object $db Database object + * @param bool $filter_edit Switch to filter by edit relationship + * @param bool $filter_view Switch to filter by view relationship + * @param bool $load_members Switch to load the members of the types + * + * @return array + * + */ + public static function getRelationshipsByTypes(&$member_types, $db, $filter_edit = false, $filter_view = true, $load_members = true) + { + // little function to get types + $getTypes = function($type) { return (isset($type)) ? ((self::checkJson($type)) ? json_decode($type, true) : ((self::checkArray($type)) ? $type : false)) : false; }; + // get this member types + if (($member_types = $getTypes($member_types)) === false || (($user_types = $getTypes(self::getVar('member', JFactory::getUser()->id, 'user', 'type'))) === false || !self::checkArray($user_types) && ($filter_edit || $filter_view))) + { + return false; + } + // check that we have the database object + if (!$db) + { + // get DB + $db = JFactory::getDBO(); + } + // get types that allow relationships + $query = $db->getQuery(true); + $query->select(array('a.id', 'a.name', 'a.description', 'a.type', 'a.edit_relationship', 'a.view_relationship', 'a.field_type', 'a.communicate')); + $query->from('#__membersmanager_type AS a'); + $query->where($db->quoteName('a.published') . ' >= 1'); + $query->where($db->quoteName('a.add_relationship') . ' = 1'); + $db->setQuery($query); + $db->execute(); + // only continue if we have member types and all relationship types + if (($types = $db->loadObjectList('id')) !== false && self::checkArray($types)) + { + // our little function to check if two arrays intersect on values + $intersect = function ($a, $b) { $b = array_flip($b); foreach ($a as $v) { if (isset($b[$v])) return true; } return false; }; + // the bucket + $bucket = array(); + // get all types related to this member + foreach($types as $id => $value) + { + if (($value->type = $getTypes($value->type)) !== false && $intersect($member_types, $value->type) + && (($value->view_relationship = $getTypes($value->view_relationship)) !== false && $intersect($user_types, $value->view_relationship) || !$filter_view) + && (($value->edit_relationship = $getTypes($value->edit_relationship)) !== false && $intersect($user_types, $value->edit_relationship) || !$filter_edit)) + { + // set the type + $bucket[$id] = $value; + if ($load_members) + { + // now get all members that belong to this type + $bucket[$id]->members = self::getMembersByType($id, $db); + } + } + } + // return if we found any + if (self::checkArray($bucket)) + { + return $bucket; + } + } + return false; + } + + + /** + * get the relationships by member + * + * @param object $member Member ID + * @param object $db Database object + * @param string $direction The relationship direction + * + * @return array + * + */ + public static function getRelationshipsByMember(&$member, $db, $direction = 'member') + { + // always check that we have an ID + if (!is_numeric($member) || $member == 0) + { + return false; + } + // check that we have the database object + if (!$db) + { + // get DB + $db = JFactory::getDBO(); + } + // set the direction relationship + $_direction = 'relation'; + if ('relation' === $direction) + { + $_direction = 'member'; + } + // get types that allow relationships + $query = $db->getQuery(true); + $query->select(array('a.' . $_direction, 'a.type')); + $query->from('#__membersmanager_relation_map AS a'); + $query->where($db->quoteName('a.' . $direction) . ' = ' . (int) $member); + $db->setQuery($query); + $db->execute(); + // only continue if we have member relationships + if (($relationships = $db->loadObjectList()) !== false && self::checkArray($relationships)) + { + // the bucket + $bucket = array(); + // sort by types + foreach($relationships as $relationship) + { + if (!isset($bucket[$relationship->type])) + { + $bucket[$relationship->type] = array(); + } + // set the type + $bucket[$relationship->type][$relationship->{$_direction}] = $relationship->{$_direction}; + } + return $bucket; + } + return false; + } + + + /** + * The Access Memory + * + * @var array + */ + protected static $accessMemory = array(); + + /** + * The Key to Access Memory + * + * @var string + */ + protected static $acK3y; + + /** + * Get a user Access Types/Groups * * @param mix $id The the user ID/object * @param int $type The type of access to return (1 = type, 2 = groups) @@ -158,11 +629,6 @@ abstract class MembersmanagerHelper */ public static function getAccess($user = null, $type = 1, $db = null) { - // get DB - if (!$db) - { - $db = JFactory::getDBO(); - } // get user if (!self::checkObject($user)) { @@ -175,113 +641,51 @@ abstract class MembersmanagerHelper $user = JFactory::getUser(); } } - // function to setup the group array - $getGroups = function ($groups) { - // convert to array - if (self::checkJson($groups)) + // check memory first + self::$acK3y = md5($user->get('id', 'not_set') . '_' . $type); + if (isset(self::$accessMemory[self::$acK3y])) + { + return self::$accessMemory[self::$acK3y]; + } + // fallback to false + self::$accessMemory[self::$acK3y] = false; + // get DB + if (!$db) + { + $db = JFactory::getDBO(); + } + // get user Access groups + if (2 == $type) + { + self::$accessMemory[self::$acK3y] = self::getAccessGroups($user, $db); + } + elseif (1 == $type) + { + // return access types + self::$accessMemory[self::$acK3y] = self::getAccessTypes($user, $db); + } + return self::$accessMemory[self::$acK3y]; + } + + /** + * Get a user Access Groups + * + * @param object $user The user object + * @param object $db The database object + * + * @return mix array + * + */ + protected static function getAccessGroups(&$user, &$db) + { + // check if access is needed + if (!$user->authorise('core.options', 'com_membersmanager')) + { + if (($userID = $user->get('id', false)) !== false && $userID > 0 && ($types = self::getVar('member', $userID, 'user', 'type')) !== false) { - return (array) json_decode($groups, true); - } - elseif (is_numeric($groups)) - { - return array($groups); + return self::getMemberGroupsByType($types, 'groups_access'); } return false; - }; - // merge groups - $mergeGroups = function ($types) use($getGroups){ - $bucket = array(); - foreach ($types as $id => $groups) - { - $groups = $getGroups($groups); - if (self::checkArray($groups)) - { - foreach ($groups as $group) - { - $bucket[$group] = $group; - } - } - } - return $bucket; - }; - // check if access it needed - if (!$user->authorise('core.admin')) - { - // get all types - $query = $db->getQuery(true); - $query->select(array('a.id', 'a.groups_access')); - $query->from('#__membersmanager_type AS a'); - $db->setQuery($query); - $db->execute(); - // get all types - $types = $db->loadAssocList('id', 'groups_access'); - if (self::checkArray($types)) - { - $bucket = array(); - foreach ($types as $id => $groups_access) - { - $groups_access = $getGroups($groups_access); - if (self::checkArray($groups_access) && array_intersect($groups_access, $user->groups)) - { - $bucket[$id] = $id; - } - } - // return types that this member can access - if (1 == $type && self::checkArray($bucket)) - { - return $bucket; - } - elseif (self::checkArray($bucket)) - { - // get the targeted groups - $query = $db->getQuery(true); - $query->select(array('a.id', 'a.groups_target')); - $query->from('#__membersmanager_type AS a'); - $query->where('a.id IN ('. implode(',', $bucket) . ')'); - $db->setQuery($query); - $db->execute(); - // get all types - $targettypes = $db->loadAssocList('id', 'groups_target'); - if (self::checkArray($targettypes)) - { - $targetbucket = $mergeGroups($targettypes); - // return types that this member can access - if (self::checkArray($targetbucket)) - { - return $targetbucket; - } - } - } - } - return false; - } - // return all types/groups - $query = $db->getQuery(true); - if (1 == $type) - { - $query->select(array('a.id')); - } - else - { - $query->select(array('a.id', 'a.groups_target')); - } - $query->from('#__membersmanager_type AS a'); - $db->setQuery($query); - $db->execute(); - if (1 == $type) - { - return $db->loadColumn(); - } - // get all types with group target - $types = $db->loadAssocList('id', 'groups_target'); - if (self::checkArray($types)) - { - $bucket = $mergeGroups($types); - // return types that this member can access - if (self::checkArray($bucket)) - { - return $bucket; - } } // return all groups $query = $db->getQuery(true); @@ -293,13 +697,131 @@ abstract class MembersmanagerHelper } /** - * set the session defaults if not set - **/ - protected static function setSessionDefaults() + * Get a user Access Types + * + * @param object $user The user object + * @param object $db The database object + * + * @return mix array + * + */ + protected static function getAccessTypes(&$user, &$db) { - // noting for now - return true; + // check if access is needed + if (!$user->authorise('core.options', 'com_membersmanager')) + { + // get all types in system + $query = $db->getQuery(true); + $query->select(array('a.id', 'a.groups_target')); // groups_target = type_link + $query->from('#__membersmanager_type AS a'); + $query->where($db->quoteName('a.published') . ' >= 1'); + // also filter by access (will keep an eye on this) + $groups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $groups . ')'); + $db->setQuery($query); + $db->execute(); + // get all types + $types = $db->loadAssocList('id', 'groups_target'); + // make sure we have types, and user access groups + if (self::checkArray($types) && ($groups_access = self::getAccessGroups($user, $db)) !== false) + { + // function to setup the group array + $setGroups = function ($groups) { + // convert to array + if (self::checkJson($groups)) + { + return (array) json_decode($groups, true); + } + elseif (is_numeric($groups)) + { + return array($groups); + } + return false; + }; + // our little function to check if two arrays intersect on values + $intersect = function ($a, $b) { $b = array_flip($b); foreach ($a as $v) { if (isset($b[$v])) return true; } return false; }; + // type bucket + $bucketTypes = array(); + foreach ($types as $id => $groups_target) + { + $groups_target = $setGroups($groups_target); + if (self::checkArray($groups_target) && $intersect($groups_target, $groups_access)) + { + $bucketTypes[$id] = $id; + } + } + // check if we found any + if (self::checkArray($bucketTypes)) + { + return $bucketTypes; + } + } + return false; + } + // return all types + $query = $db->getQuery(true); + $query->select(array('a.id')); + $query->from('#__membersmanager_type AS a'); + $query->where($db->quoteName('a.published') . ' >= 1'); + $db->setQuery($query); + $db->execute(); + return $db->loadColumn(); } + + /** + * Get a user Access Types/Groups + * + * @param mix $types The member types + * @param string $groupType The type of groups + * + * @return mix array + * + */ + public static function getMemberGroupsByType($types, $groupType = 'groups_target') + { + // convert type json to array + if (self::checkJson($types)) + { + $types = json_decode($types, true); + } + // convert type int to array + if (is_numeric($types) && $types > 0) + { + $types = array($types); + } + // make sure we have an array + if (self::checkArray($types)) + { + $groups = array(); + foreach ($types as $type) + { + // get the target groups + $groups_target = self::getVar('type', $type, 'id', $groupType); + // convert to array + if (self::checkJson($groups_target)) + { + $groups_target = (array) json_decode($groups_target, true); + } + // convert type int to array + if (is_numeric($groups_target)) + { + $groups_target = array((int) $groups_target); + } + // make sure we have an array + if (self::checkArray($groups_target)) + { + $groups[] = $groups_target; + } + } + // make sure we have an array + if (self::checkArray($groups)) + { + return self::mergeArrays($groups); + } + } + return false; + } + /** * Change to nice fancy date @@ -349,6 +871,30 @@ abstract class MembersmanagerHelper return date('G:i',$time); } + /** + * set the date as 2004/05 (for charts) + */ + public static function setYearMonth($date) + { + if (!self::isValidTimeStamp($date)) + { + $date = strtotime($date); + } + return date('Y/m', $date); + } + + /** + * set the date as 2004/05/03 (for charts) + */ + public static function setYearMonthDay($date) + { + if (!self::isValidTimeStamp($date)) + { + $date = strtotime($date); + } + return date('Y/m/d', $date); + } + /** * Check if string is a valid time stamp */ @@ -358,7 +904,71 @@ abstract class MembersmanagerHelper && ($timestamp <= PHP_INT_MAX) && ($timestamp >= ~PHP_INT_MAX); } - + + + /** + * get between + * + * @param string $content The content to search + * @param string $start The starting value + * @param string $end The ending value + * @param string $default The default value if none found + * + * @return string On success / empty string on failure + * + */ + public static function getBetween($content, $start, $end, $default = '') + { + $r = explode($start, $content); + if (isset($r[1])) + { + $r = explode($end, $r[1]); + return $r[0]; + } + return $default; + } + + /** + * get all between + * + * @param string $content The content to search + * @param string $start The starting value + * @param string $end The ending value + * + * @return array On success + * + */ + public static function getAllBetween($content, $start, $end) + { + // reset bucket + $bucket = array(); + for ($i = 0; ; $i++) + { + // search for string + $found = self::getBetween($content,$start,$end); + if (self::checkString($found)) + { + // add to bucket + $bucket[] = $found; + // build removal string + $remove = $start.$found.$end; + // remove from content + $content = str_replace($remove,'',$content); + } + else + { + break; + } + // safety catch + if ($i == 500) + { + break; + } + } + // only return unique array of values + return array_unique($bucket); + } + /** * the Butler @@ -388,6 +998,10 @@ abstract class MembersmanagerHelper **/ public static function set($key, $value) { + if (!isset(self::$session) || !self::checkObject(self::$session)) + { + self::$session = JFactory::getSession(); + } // set to local memory to speed up program self::$localSession[$key] = $value; // load to session for later use @@ -399,6 +1013,10 @@ abstract class MembersmanagerHelper **/ public static function get($key, $default = null) { + if (!isset(self::$session) || !self::checkObject(self::$session)) + { + self::$session = JFactory::getSession(); + } // check if in local memory if (!isset(self::$localSession[$key])) { @@ -435,6 +1053,44 @@ abstract class MembersmanagerHelper } + /** + * open base64 string if stored as base64 + * + * @param string $data The base64 string + * @param string $key We store the string with that suffix :) + * @param string $default The default switch + * + * @return string The opened string + * + */ + public static function openValidBase64($data, $key = '__.o0=base64=Oo.__', $default = 'string') + { + // check that we have a string + if (self::checkString($data)) + { + // check if we have a key + if (self::checkString($key)) + { + if (strpos($data, $key) !== false) + { + return base64_decode(str_replace($key, '', $data)); + } + } + // fallback to this, not perfect method + if (base64_encode(base64_decode($data, true)) === $data) + { + return base64_decode($data); + } + } + // check if we should just return the string + if ('string' === $default) + { + return $data; + } + return $default; + } + + /** * the locker * @@ -779,26 +1435,53 @@ abstract class MembersmanagerHelper return $open; } + /** + * The Dynamic Data Array + * + * @var array + */ protected static $dynamicData = array(); + /** + * Set the Dynamic Data + * + * @param string $data The data to update + * @param array $placeholders The placeholders to use to update data + * + * @return string of updated data + * + */ public static function setDynamicData($data, $placeholders) { - $keyMD5 = md5($data.json_encode($placeholders)); - if (!isset(self::$dynamicData[$keyMD5])) + // make sure data is a string & placeholders is an array + if (self::checkString($data) && self::checkArray($placeholders)) { - if (self::checkArray($placeholders)) + // store in memory in case it is build multiple times + $keyMD5 = md5($data.json_encode($placeholders)); + if (!isset(self::$dynamicData[$keyMD5])) { + // remove all values that are not strings (just to be safe) + $placeholders = array_filter($placeholders, function ($val){ if (self::checkArray($val) || self::checkObject($val)) { return false; } return true; }); + // model (basic) based on logic self::setTheIF($data, $placeholders); + // update the string and store in memory self::$dynamicData[$keyMD5] = str_replace(array_keys($placeholders), array_values($placeholders), $data); } - else - { - self::$dynamicData[$keyMD5] = $data; - } + // return updated string + return self::$dynamicData[$keyMD5]; } - return self::$dynamicData[$keyMD5]; + return $data; } + /** + * Set the IF statements + * + * @param string $string The string to update + * @param array $placeholders The placeholders to use to update string + * + * @return void + * + */ protected static function setTheIF(&$string, $placeholders) { // only normal if endif @@ -843,6 +1526,15 @@ abstract class MembersmanagerHelper } } + /** + * Set the remainder IF + * + * @param array $match The match search + * @param array $placeholders The placeholders to use to match + * + * @return string of remainder + * + */ protected static function remainderIF(&$match, &$placeholders) { // default we keep nothing @@ -873,7 +1565,7 @@ abstract class MembersmanagerHelper { $keep = addcslashes($match[$length - 1], '$'); } - return $keep; + return $keep; } @@ -1148,6 +1840,39 @@ abstract class MembersmanagerHelper } + /** + * Write a file to the server + * + * @param string $path The path and file name where to safe the data + * @param string $data The data to safe + * + * @return bool true On success + * + */ + public static function writeFile($path, $data) + { + $klaar = false; + if (self::checkString($data)) + { + // open the file + $fh = fopen($path, "w"); + if (!is_resource($fh)) + { + return $klaar; + } + // write to the file + if (fwrite($fh, $data)) + { + // has been done + $klaar = true; + } + // close file. + fclose($fh); + } + return $klaar; + } + + /** * @return array of link options */ @@ -1641,6 +2366,69 @@ abstract class MembersmanagerHelper return self::$companyDetails[$method]; } + /** + * Get/load the component helper class if not already loaded + * + * @param string $_component The component element name + * + * @return string The helper class name + * + */ + public static function getHelperClass($_component) + { + // make sure we have com_ + if (strpos($_component, 'com_') !== false) + { + // get component name + $component = str_replace('com_', '', $_component); + } + else + { + // get the component name + $component = $_component; + // set the element name + $_component = 'com_' . $component; + } + // build component helper name + $componentHelper = self::safeString($component, 'F') . 'Helper'; + // check if it is already set + if (!class_exists($componentHelper)) + { + // set the correct path focus + $focus = JPATH_ADMINISTRATOR; + // check if we are in the site area + if (JFactory::getApplication()->isSite()) + { + // set admin path + $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; + // change the focus + $focus = JPATH_ROOT; + } + // set path based on focus + $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; + // check if file exist, if not try admin again. + if (file_exists($path)) + { + // make sure to load the helper + JLoader::register($componentHelper, $path); + } + // fallback option + elseif (isset($adminPath) && file_exists($adminPath)) + { + // make sure to load the helper + JLoader::register($componentHelper, $adminPath); + } + else + { + // could not find this + return false; + } + } + // success + return $componentHelper; + } + + /** * get a report * @@ -1679,6 +2467,23 @@ abstract class MembersmanagerHelper $placeholders = self::mergeArrays($placeholders); // get the ID $divID = self::randomkey(10); + // update the template with placeholders + $data = self::setDynamicData($template, $placeholders); + // make sure all placeholders are removed + if (strpos($data, '[') !== false && strpos($data, ']') !== false) + { + // get the prefix + $prefix = JComponentHelper::getParams($_component)->get('placeholder_prefix', str_replace('com_', '', $_component)); + // get the left over placeholders + $left = self::getAllBetween($data, '[' . $prefix, ']'); + if (self::checkArray($left)) + { + foreach ($left as $remove) + { + $data = str_replace('[' . $prefix . $remove . ']', '', $data); + } + } + } // get the global settings if (!self::checkObject(self::$params)) { @@ -1688,14 +2493,10 @@ abstract class MembersmanagerHelper $uikitVersion = self::$params->get('uikit_version', 2); if (3 == $uikitVersion) { - return '' . JText::_('COM_MEMBERSMANAGER_PRINT') . '
' . - self::setDynamicData($template, $placeholders) . - '
'; + return '' . JText::_('COM_MEMBERSMANAGER_PRINT') . '
' . $data . '
'; } // return html - return '
' . - self::setDynamicData($template, $placeholders) . - '
'; + return '
' . $data . '
'; } } return false; @@ -1718,40 +2519,10 @@ abstract class MembersmanagerHelper // check if we are in the correct class if ('com_membersmanager' !== $_component) { - // get component name - $component = str_replace('com_', '', $_component); - // build component helper name - $componentHelper = self::safeString($component, 'F') . 'Helper'; - // check if it is already set - if (!class_exists($componentHelper, FALSE)) - { - // set the correct path focus - $focus = JPATH_ADMINISTRATOR; - if (JFactory::getApplication()->isSite()) - { - // set admin path - $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // change the focus - $focus = JPATH_ROOT; - } - // set path based on focus - $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // check if file exist, if not try admin again. - if (file_exists($path)) - { - // make sure to load the helper - JLoader::register($componentHelper, $path); - } - elseif (isset($adminPath) && file_exists($adminPath)) // fallback option - { - // make sure to load the helper - JLoader::register($componentHelper, $adminPath); - } - } // check if the class and method exist - if (class_exists($componentHelper) && method_exists($componentHelper, 'getTemplate')) + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getTemplate')) { - return $componentHelper::getTemplate($type, $default, $target); + return $helperClass::getTemplate($type, $default, $target); } return false; } @@ -1773,56 +2544,29 @@ abstract class MembersmanagerHelper * @param string $method The type of values to return * @param string $filter The kind of filter (to return only values required) * @param string $masterkey The master key + * @param string $table The target form table + * @param int $qty The qty items to return * * @return array/object based on $method * */ - public static function getAnyFormDetails($memberID, $type = 'member', $_component = 'com_membersmanager', $method = 'array', $filter = 'none', $masterkey = 'member') + public static function getAnyFormDetails($memberID, $type = 'member', $_component = 'com_membersmanager', $method = 'array', $filter = 'none', $masterkey = 'member', $table = 'form', $qty = 0) { + // set class name + $class = self::safeString($table, 'W'); // check if we are in the correct class if ('com_membersmanager' !== $_component) { - // get component name - $component = str_replace('com_', '', $_component); - // build component helper name - $componentHelper = self::safeString($component, 'F') . 'Helper'; - // check if it is already set - if (!class_exists($componentHelper, FALSE)) - { - // set the correct path focus - $focus = JPATH_ADMINISTRATOR; - if (JFactory::getApplication()->isSite()) - { - // set admin path - $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // change the focus - $focus = JPATH_ROOT; - } - // set path based on focus - $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // check if file exist, if not try admin again. - if (file_exists($path)) - { - // make sure to load the helper - JLoader::register($componentHelper, $path); - } - elseif (isset($adminPath) && file_exists($adminPath)) - { - // make sure to load the helper - JLoader::register($componentHelper, $adminPath); - } - } // check if the class and method exist - if (class_exists($componentHelper) && method_exists($componentHelper, 'getFormDetails')) + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'get' . $class . 'Details')) { - return $componentHelper::getFormDetails($memberID, $type, 'form', $method, $filter, $masterkey); + return $helperClass::{'get' . $class . 'Details'}($memberID, $type, $table, $method, $filter, $masterkey, $qty); } - return false; } // check if the class and method exist - elseif (method_exists(__CLASS__, 'getFormDetails')) + elseif (method_exists(__CLASS__, 'get' . $class . 'Details')) { - return self::getFormDetails($memberID, $type, 'form', $method, $filter, $masterkey); + return self::{'get' . $class . 'Details'}($memberID, $type, $table, $method, $filter, $masterkey, $qty); } return false; } @@ -1843,42 +2587,11 @@ abstract class MembersmanagerHelper // check if we are in the correct class if ('com_membersmanager' !== $_component) { - // get component name - $component = str_replace('com_', '', $_component); - // build component helper name - $componentHelper = self::safeString($component, 'F') . 'Helper'; - // check if it is already set - if (!class_exists($componentHelper, FALSE)) - { - // set the correct path focus - $focus = JPATH_ADMINISTRATOR; - if (JFactory::getApplication()->isSite()) - { - // set admin path - $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // change the focus - $focus = JPATH_ROOT; - } - // set path based on focus - $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // check if file exist, if not try admin again. - if (file_exists($path)) - { - // make sure to load the helper - JLoader::register($componentHelper, $path); - } - elseif (isset($adminPath) && file_exists($adminPath)) // fallback option - { - // make sure to load the helper - JLoader::register($componentHelper, $adminPath); - } - } // check if the class and method exist - if (class_exists($componentHelper) && method_exists($componentHelper, 'getCompanyDetails')) + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getCompanyDetails')) { - return $componentHelper::getCompanyDetails($method, $filter); + return $helperClass::getCompanyDetails($method, $filter); } - return false; } // check if the class and method exist elseif (method_exists(__CLASS__, 'getCompanyDetails')) @@ -1889,6 +2602,102 @@ abstract class MembersmanagerHelper } + /** + * Get Any chart code + * + * @param string $key The unique key/id_name + * @param string $dataTable The data table for the chart + * @param string $dataTable The details for the chart + * @param string $filter The kind of filter (to return only values required) + * @param string $_component The component element name + * + * @return string The dataTable + * + */ + public static function getAnyChartCode($key, $dataTable, $chartDetails, $filter = 'null', $_component = 'com_membersmanager') + { + // check if we are in the correct class + if ('com_membersmanager' !== $_component) + { + // check if the class and method exist + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getChartCode')) + { + return $helperClass::getChartCode($key, $dataTable, $chartDetails, $filter); + } + } + // check if the class and method exist + elseif (method_exists(__CLASS__, 'getChartCode')) + { + return self::getChartCode($key, $dataTable, $chartDetails, $filter); + } + return false; + } + + + /** + * Get Any Multi Chart dataTable + * + * @param int $memberId The member ID + * @param int $target The type of chart retrieval behavior + * @param string $key The chart key + * @param string $_component The component element name + * @param array $args Options to override chart details + * 'dataTable' => $template + * 'number' => $number + * + * @return string The dataTable + * + */ + public static function getAnyMultiChartDataTable($memberID, $target, $key = null, $_component = 'com_membersmanager', $args = null) + { + // check if we are in the correct class + if ('com_membersmanager' !== $_component) + { + // check if the class and method exist + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getMultiChartDataTable')) + { + return $helperClass::getMultiChartDataTable($memberID, $target, $key, $args); + } + } + // check if the class and method exist + elseif (method_exists(__CLASS__, 'getMultiChartDataTable')) + { + return self::getMultiChartDataTable($memberID, $target, $key, $args); + } + return false; + } + + + /** + * Get Any Available Charts + * + * @param string $key The chart key + * @param int $target The type of chart retrieval behavior + * @param string $_component The component element name + * + * @return array + * + */ + public static function getAnyAvailableCharts($key = null, $target = 1, $_component = 'com_membersmanager') + { + // check if we are in the correct class + if ('com_membersmanager' !== $_component) + { + // check if the class and method exist + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getAvailableCharts')) + { + return $helperClass::getAvailableCharts($key, $target); + } + } + // check if the class and method exist + elseif (method_exists(__CLASS__, 'getAvailableCharts')) + { + return self::getAvailableCharts($key, $target); + } + return false; + } + + /** * Get Member forms * @@ -1952,6 +2761,13 @@ abstract class MembersmanagerHelper */ protected static $memberDetails = array(); + /** + * The current return number + * + * @var int + */ + public static $returnNumber; + /** * The global details key (set per/query) * @@ -1968,11 +2784,12 @@ abstract class MembersmanagerHelper * @param string $method The type of values to return * @param string $filter The kind of filter (to return only values required) * @param string $masterkey The master key for many values in the member table + * @param int $qty The qty items to return * * @return array/object based on $method * */ - public static function getMemberDetails($id, $type = 'id', $table = 'member', $method = 'array', $filter = 'none', $masterkey = 'member') + public static function getMemberDetails($id, $type = 'id', $table = 'member', $method = 'array', $filter = 'none', $masterkey = 'member', $qty = 0) { // always make sure that we have a member column if ($table !== 'member' && $type !== $masterkey) @@ -1985,13 +2802,15 @@ abstract class MembersmanagerHelper $type = $masterkey; $table = 'member'; } + // get the user object + $user = JFactory::getUser(); // get database object $db = JFactory::getDbo(); + // get the database columns of this table + $columns = $db->getTableColumns("#__membersmanager_member", false); // if not id validate column if ($type !== 'id' && $type !== $masterkey) { - // get the database columns of this table - $columns = $db->getTableColumns("#__membersmanager_member", false); // check if the type is found if (!isset($columns[$type])) { @@ -2017,7 +2836,7 @@ abstract class MembersmanagerHelper $type = $masterkey; } // set the global key - self::$k3y = $id.$method.$filter; + self::$k3y = $id.$method.$filter.$qty; // we will check this (qty) it may not be ideal (TODO) // check if we have the member details in memory if (is_numeric($id) && $id > 0 && !isset(self::$memberDetails[self::$k3y])) { @@ -2042,6 +2861,7 @@ abstract class MembersmanagerHelper // check if we have a selection if (isset($selection) && self::checkArray($selection)) { + // do permission view purge (TODO) // set the selection $query->select($db->quoteName(array_keys($selection), array_values($selection))); // From the membersmanager_member table @@ -2051,24 +2871,48 @@ abstract class MembersmanagerHelper { self::joinMemberDetails($query, $filter, $db); } + // Implement View Level Access (if set in table) + if (!$user->authorise('core.options', '[[[com_component]]]') && isset($columns['access'])) + { + // ensure to always filter by access + $accessGroups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $accessGroups . ')'); + } // check if we have more get where details if (method_exists(__CLASS__, "whereMemberDetails")) { self::whereMemberDetails($query, $filter, $db); } + // check if we have more order details + if (method_exists(__CLASS__, "orderMemberDetails")) + { + self::orderMemberDetails($query, $filter, $db); + } + // always order so to insure last added is first by default + else + { + $query->order('a.id ASC'); + } + // limit the return + if($qty > 1) + { + $query->setLimit($qty); + } // get by type ID $query->where('a.' . $type . ' = ' . (int) $id); $db->setQuery($query); $db->execute(); - $numberRows = $db->getNumRows(); - if ($numberRows) + self::$returnNumber = $db->getNumRows(); + if (self::$returnNumber) { if ('object' == $method) { // if one to one - if ($relations == 1 || $numberRows == 1) + if ($qty == 1 || $relations == 1 || self::$returnNumber == 1) { self::$memberDetails[self::$k3y] = $db->loadObject(); + // we retrieved only 1 + self::$returnNumber = 1; } // if one to many (so we must return many) else @@ -2079,9 +2923,11 @@ abstract class MembersmanagerHelper else { // if one to one - if ($relations == 1 || $numberRows == 1) + if ($qty == 1 || $relations == 1 || self::$returnNumber == 1) { self::$memberDetails[self::$k3y] = $db->loadAssoc(); + // we retrieved only 1 + self::$returnNumber = 1; } // if one to many (so we must return many) else @@ -2098,11 +2944,11 @@ abstract class MembersmanagerHelper // check if we must model the details elseif (method_exists(__CLASS__, "modelMemberDetails")) { - self::modelMemberDetails($id, $method, $filter, $numberRows, $db); + self::modelMemberDetails($id, $method, $filter, $db); // check if we must remove some details after modeling if (method_exists(__CLASS__, "removeMemberDetails")) { - self::removeMemberDetails($id, $method, $filter, $numberRows, $db); + self::removeMemberDetails($id, $method, $filter, $db); } } } @@ -2115,19 +2961,26 @@ abstract class MembersmanagerHelper } + /** + * the global chart array + * + * @var array + * + */ + public static $globalMemberChartArray = array(); + /** * Model the member details/values * * @param object $id The the member ID * @param string $method The type of values to return * @param string $filter The kind of filter (to return only values required) - * @param int $numberRows The number of rows * @param object $db The database object * * @return void * */ - protected static function modelMemberDetails($id, $method, $filter, $numberRows, $db = null) + protected static function modelMemberDetails($id, $method, $filter, $db = null) { // check that we have values if (method_exists(__CLASS__, 'getSelection') && isset(self::$memberDetails[self::$k3y]) && self::$memberDetails[self::$k3y]) @@ -2141,7 +2994,12 @@ abstract class MembersmanagerHelper // check if we have params to model if (method_exists(__CLASS__, "paramsModelMemberDetails")) { - self::paramsModelMemberDetails($_builder, $method, $numberRows); + self::paramsModelMemberDetails($_builder, $method); + } + // check if we have subforms to model + if (method_exists(__CLASS__, "subformModelMemberDetails")) + { + self::subformModelMemberDetails($_builder, $method); } // get values that must be set (not SQL values) $builder = array_filter( @@ -2181,7 +3039,7 @@ abstract class MembersmanagerHelper if (self::checkArray($valueKeys)) { // start the modeling - if ($numberRows == 1) + if (self::$returnNumber == 1) { $object = new JObject; foreach ($valueKeys as $valueKey) @@ -2292,7 +3150,7 @@ abstract class MembersmanagerHelper } else { - if ($numberRows == 1) + if (self::$returnNumber == 1) { // work with object if ('object' === $method && isset(self::$memberDetails[self::$k3y]->{$_build[1]})) @@ -2372,19 +3230,245 @@ abstract class MembersmanagerHelper } } // check if we have labels to model - if (method_exists(__CLASS__, "labelModelMemberDetails") && property_exists(__CLASS__, 'memberParams')) + if (method_exists(__CLASS__, "labelModelMemberDetails")) { - self::labelModelMemberDetails($_builder, $method, $numberRows); + self::labelModelMemberDetails($_builder, $method); } // check if we have templates to model if (method_exists(__CLASS__, "templateModelMemberDetails") && property_exists(__CLASS__, 'memberParams')) { - self::templateModelMemberDetails($_builder, $method, $numberRows); + self::templateModelMemberDetails($_builder, $method); + } + // check if we have charts to model (must be last after all data is set) + if (method_exists(__CLASS__, "chartModelMemberDetails")) + { + self::chartModelMemberDetails($_builder, $method, $filter); + } + elseif (method_exists(__CLASS__, "multiChartModelMemberDetails")) + { + self::multiChartModelMemberDetails($_builder, $method, $filter); } } } + /** + * Label Model the member details/values + * + * @param array $builder The selection array + * @param string $method The type of values to return + * + * @return void + * + */ + protected static function labelModelMemberDetails($builder, $method) + { + // get values that must be set (not SQL values) + $builder = array_filter( + $builder, + function ($key) { + return strpos($key, 'Label->'); + }, + ARRAY_FILTER_USE_KEY + ); + // start the builder + if (self::checkArray($builder)) + { + // prep for placeholders + $f = ''; + $b = ''; + if ('placeholder' === $method) + { + // get the placeholder prefix + $prefix = self::$params->get('placeholder_prefix', 'membersmanager'); + $f = '[' . $prefix . '_'; + $b = ']'; + } + // loop builder + foreach ($builder as $build => $set) + { + // get the label key + $build = str_replace('setLabel->', '', $build); + // check if this is a single or multi array + if (self::$returnNumber == 1) + { + // work with object + if ('object' === $method) + { + self::$memberDetails[self::$k3y]->{$set} = self::setLabelModelMemberDetails($build); + } + // work with array + elseif (self::checkArray(self::$memberDetails[self::$k3y]) && isset(self::$memberDetails[self::$k3y][$f.$build.$b])) + { + self::$memberDetails[self::$k3y][$set] = self::setLabelModelMemberDetails($build); + } + } + elseif (self::checkArray(self::$memberDetails[self::$k3y])) + { + foreach (self::$memberDetails[self::$k3y] as $_nr => $details) + { + // work with object + if ('object' === $method && isset(self::$memberDetails[self::$k3y][$_nr]->{$build})) + { + self::$memberDetails[self::$k3y][$_nr]->{$set} = self::setLabelModelMemberDetails($build); + } + // work with array + elseif (self::checkArray(self::$memberDetails[self::$k3y][$_nr]) && isset(self::$memberDetails[self::$k3y][$_nr][$f.$build.$b])) + { + self::$memberDetails[self::$k3y][$_nr][$set] = self::setLabelModelMemberDetails($build); + } + } + } + } + } + } + + /** + * Set the Label to the member details/values + * + * @param string $key The key of the setting label + * + * @return mix + * + */ + protected static function setLabelModelMemberDetails($key) + { + // make sure we have the template + if (property_exists(__CLASS__, 'formParams') && isset(self::$formParams[$key]) && isset(self::$memberParams[$key]['label']) && self::checkString(self::$memberParams[$key]['label'])) + { + return JText::_(self::$memberParams[$key]['label']); + } + // check if this value is part of the admin form + $LABLE = 'COM_MEMBERSMANAGER_FORM_' . self::safeString($key, 'U') . '_LABEL'; + $label = JText::_($LABLE); + // little workaround for now + if ($LABLE === $label) + { + return self::safeString($key, 'Ww'); + } + return $label; + } + + + /** + * Multi Chart Model the member details/values + * + * @param array $builder The selection array + * @param string $method The type of values to return + * @param string $filter The kind of filter (to return only values required) + * + * @return void + * + */ + protected static function multiChartModelMemberDetails($builder, $method, $filter) + { + // get values that must be set (not SQL values) + $builder = array_filter( + $builder, + function ($key) { + return strpos($key, 'MultiChart->'); + }, + ARRAY_FILTER_USE_KEY + ); + // start the builder + if (self::checkArray($builder)) + { + // prep for placeholders + $f = ''; + $b = ''; + if ('placeholder' === $method) + { + // get the placeholder prefix + $prefix = self::$params->get('placeholder_prefix', 'membersmanager'); + $f = '[' . $prefix . '_'; + $b = ']'; + } + // set params key + // loop builder + foreach ($builder as $build => $set) + { + // get the chart key + $build = str_replace('setMultiChart->', '', $build); + // check if this is a single or multi array + if (self::$returnNumber == 1) + { + // work with object + if ('object' === $method) + { + self::$memberDetails[self::$k3y]->{$set} = self::setMultiChartModelMemberDetails(self::$memberDetails[self::$k3y]->{$f . 'id' . $b}, $build, $filter); + } + // work with array + elseif (self::checkArray(self::$memberDetails[self::$k3y])) + { + self::$memberDetails[self::$k3y][$set] = self::setMultiChartModelMemberDetails(self::$memberDetails[self::$k3y][$f . 'id' . $b], $build, $filter); + } + } + elseif (self::checkArray(self::$memberDetails[self::$k3y])) + { + foreach (self::$memberDetails[self::$k3y] as $_nr => $details) + { + // work with object + if ('object' === $method) + { + self::$memberDetails[self::$k3y][$_nr]->{$set} = self::setMultiChartModelMemberDetails(self::$memberDetails[self::$k3y][$_nr]->{$f . 'id' . $b}, $build, $filter); + } + // work with array + elseif (self::checkArray(self::$memberDetails[self::$k3y][$_nr])) + { + self::$memberDetails[self::$k3y][$_nr][$set] = self::setMultiChartModelMemberDetails(self::$memberDetails[self::$k3y][$_nr][$f . 'id' . $b], $build, $filter); + } + } + } + } + } + } + + /** + * Set the multi chart to the member details/values + * + * @param object/array $placeholders The placeholders + * @param string $key The key of the setting chart + * @param string $filter The kind of filter (to return only values required) + * + * @return string + * + */ + protected static function setMultiChartModelMemberDetails($id, $keyString, &$filter) + { + // get the key array + $keyArray = explode('\^/', $keyString); + // get the chart, the data table and the code + if (($cart = self::getAnyAvailableCharts($keyArray[0], $keyArray[2], $keyArray[1])) !== false && + ($dataTable = self::getAnyMultiChartDataTable($id, $keyArray[2], $keyArray[0], $keyArray[1])) !== '' && + ($code = self::getAnyChartCode($keyArray[0] . self::safeString($id), $dataTable, $cart['details'], $filter, $keyArray[1])) !== false) + { + if ('email' === $filter && isset($code['span'])) + { + // set to global chart array + self::$globalMemberChartArray[$code['id_name']] = $code; + // return placeholder + return $code['span']; + } + // build html + $html = array(); + $html[] = $code['div']; + $html[] = ''; + // return the chart code/html + return implode("\n", $html); + } + return ''; + } + + + /** + * The Member Name Memory + * + * @var array + */ + protected static $memberNames = array(); + /** * Get the members name * @@ -2392,12 +3476,36 @@ abstract class MembersmanagerHelper * @param int $user The user ID * @param string $name The name * @param string $surname The surname + * @param string $default The default * * @return string the members name * */ - public static function getMemberName($id, $user = null, $name = null, $surname = null) + public static function getMemberName($id = null, $user = null, $name = null, $surname = null, $default = 'No Name') { + // check if member ID is null, then get member ID + if (!$id || !is_numeric($id)) + { + if (!$user || !is_numeric($user) || ($id = self::getVar('member', $user, 'user', 'id', '=', 'membersmanager')) === false || !is_numeric($id) || $id == 0) + { + // check if a was name given + if (self::checkstring($name)) + { + $default = $name; + } + // always set surname if given + if (self::checkString($surname)) + { + $default += ' ' . $surname; + } + return $default; + } + } + // check if name in memory + if (isset(self::$memberNames[$id])) + { + return self::$memberNames[$id]; + } // always get surname if (!self::checkString($surname)) { @@ -2409,19 +3517,125 @@ abstract class MembersmanagerHelper // check name given if (self::checkstring($name)) { - return $name . ' ' . $surname; + $memberName = $name . ' ' . $surname; } // check user given - elseif ((is_numeric($user) && $user > 0) || (is_numeric($id) && $id > 0 && ($user = self::getVar('member', $id, 'id', 'user', '=', 'membersmanager')) !== false && $user > 0)) + elseif ((is_numeric($user) && $user > 0) || (($user = self::getVar('member', $id, 'id', 'user', '=', 'membersmanager')) !== false && $user > 0)) { - return JFactory::getUser($user)->name . ' ' . $surname; + $memberName = JFactory::getUser($user)->name . ' ' . $surname; } // get the name - elseif (is_numeric($id) && $id > 0 && ($name = self::getVar('member', $id, 'id', 'name', '=', 'membersmanager')) !== false && self::checkstring($name)) + elseif (($name = self::getVar('member', $id, 'id', 'name', '=', 'membersmanager')) !== false && self::checkstring($name)) { - return $name . ' ' . $surname; + $memberName = $name . ' ' . $surname; } - return JText::_('COM_MEMBERSMANAGER_NO_NAME'); + // load to memory + if (isset($memberName)) + { + self::$memberNames[$id] = $memberName; + // return member name + return $memberName; + } + return $default; + } + + /** + * The Member Email Memory + * + * @var array + */ + protected static $memberEmails = array(); + + /** + * Get the members email + * + * @param int $id The member ID + * @param int $user The user ID + * @param string $default The default + * + * @return string the members email + * + */ + public static function getMemberEmail($id = null, $user = null, $default = '') + { + // check if member ID is null, then get member ID + if (!$id || !is_numeric($id)) + { + if (!$user || !is_numeric($user) || ($id = self::getVar('member', $user, 'user', 'id')) === false) + { + return $default; + } + } + // check if email in memory + if (isset(self::$memberEmails[$id])) + { + return self::$memberEmails[$id]; + } + // check user given + if ((is_numeric($user) && $user > 0) || (is_numeric($id) && $id > 0 && ($user = self::getVar('member', $id, 'id', 'user', '=', 'membersmanager')) !== false && $user > 0)) + { + $memberEmail = JFactory::getUser($user)->email; + } + // get the email + elseif (($email = self::getVar('member', $id, 'id', 'email', '=', 'membersmanager')) !== false && self::checkstring($email)) + { + $memberEmail = $email; + } + // load to memory + if (isset($memberEmail)) + { + self::$memberEmails[$id] = $memberEmail; + // return found email + return $memberEmail; + } + return $default; + } + + + /** + * get all components linked + * + * @return array of all components + * + */ + public static function getAllComponents($relation = null, $types = array('Info','Assessment')) + { + // build components array + $components = array(); + // search if the types are set and active + foreach ($types as $type) + { + if (method_exists(__CLASS__, 'get' . $type. 'Components') && ($_components = self::{'get' . $type. 'Components'}(null, null, $relation)) !== false && self::checkArray($_components)) + { + $components = self::mergeArrays(array($components, $_components)); + } + } + // if we found components return + if (self::checkArray($components)) + { + return $components; + } + return false; + } + + + /** + * get active component name + * + * @return string of component name + * + */ + public static function getComponentName($_component, $types = array('Info','Assessment')) + { + // search if the types are set and active + foreach ($types as $type) + { + if (method_exists(__CLASS__, 'get' . $type. 'ComponentName') && ($name = self::{'get' . $type. 'ComponentName'}($_component)) !== false) + { + return $name; + } + } + return false; } @@ -2433,9 +3647,9 @@ abstract class MembersmanagerHelper /** * Get available infos based on type */ - public static function getInfoAvaillable($type, $account, $multiDimensionalAllowed = true) + public static function getInfoAvaillable($types, $account, $multiDimensionalAllowed = true) { - $infos = self::getInfoComponents($type, $account); + $infos = self::getInfoComponents($types, $account); // check if we found components if (self::checkArray($infos)) { @@ -2463,9 +3677,31 @@ abstract class MembersmanagerHelper if (!isset($bucketInfos[$infoTypeName])) { $bucketInfos[$infoTypeName] = array(); + $bucketInfos[$infoTypeName][] = $component; + } + // check if this is an array set + elseif (self::checkArray($bucketInfos[$infoTypeName])) + { + // set data (one to many) + $bucketInfos[$infoTypeName][] = $component; + } + // check if this is an array set + elseif (self::checkObject($bucketInfos[$infoTypeName])) + { + $bucket_key = $infoTypeName . ' *'; + // start array if not already set + if (!isset($bucketInfos[$bucket_key])) + { + $bucketInfos[$bucket_key] = array(); + $bucketInfos[$bucket_key][] = $component; + } + // check if this is an array set + elseif (self::checkArray($bucketInfos[$bucket_key])) + { + // set data (one to many) + $bucketInfos[$bucket_key][] = $component; + } } - // set data (one to many) - $bucketInfos[$infoTypeName][] = $component; } } // return the info bucket @@ -2474,12 +3710,37 @@ abstract class MembersmanagerHelper return false; } + /** + * Get type info component name + */ + public static function getInfoComponentName($_component) + { + // see if we have components in memory + if (!self::checkArray(self::$infoComponents)) + { + // get list of components + self::$infoComponents = self::setInfoComponents(); + } + // make sure we have components + if (self::checkArray(self::$infoComponents)) + { + foreach (self::$infoComponents as $component) + { + if ($component->element === $_component) + { + return $component->name; + } + } + } + return false; + } + /** * Get type info names */ - public static function getTypeInfosNames($type, $account, $as = 'string') + public static function getTypeInfosNames($types, $account, $as = 'string') { - $infos = self::getInfoAvaillable($type, $account); + $infos = self::getInfoAvaillable($types, $account); $names = array(); if (self::checkArray($infos)) { @@ -2508,27 +3769,57 @@ abstract class MembersmanagerHelper /** * Get info components */ - public static function getInfoComponents($type = null, $account = null) + public static function getInfoComponents($types = null, $account = null, $relation = null) { + // see if we have components in memory if (!self::checkArray(self::$infoComponents)) { - // get list of Extensions + // get list of components self::$infoComponents = self::setInfoComponents(); } - // filter by type & account - if ($type && $account && self::checkArray(self::$infoComponents)) + // make sure we have components + if (self::checkArray(self::$infoComponents)) { - // filter out the components we need - return array_filter( - self::$infoComponents, - function ($component) use ($type, $account) { - // check if the component is available to this type of member - return ((isset($component->params->membersmanager_target_type) && in_array($type, (array) $component->params->membersmanager_target_type)) && - (isset($component->params->membersmanager_target_account) && in_array($account, (array) $component->params->membersmanager_target_account))); - } - ); + // convert type json to array + if ($types && self::checkJson($types)) + { + $types = json_decode($types, true); + } + // convert type int to array + if ($types && is_numeric($types) && $types > 0) + { + $types = array($types); + } + // filter by type & account + if ($types && self::checkArray($types) && $account) + { + // our little function to check if two arrays intersect on values + $intersect = function ($a, $b) { $b = array_flip($b); foreach ($a as $v) { if (isset($b[$v])) return true; } return false; }; + // filter out the components we need + return array_filter( + self::$infoComponents, + function ($component) use ($types, $account, $relation, $intersect) { + // check if the component is available to this type of member + return ((isset($component->params->membersmanager_target_type) && $intersect($types, (array) $component->params->membersmanager_target_type)) && + (isset($component->params->membersmanager_target_account) && in_array($account, (array) $component->params->membersmanager_target_account)) && + (!$relation || (is_int($relation) && $relation == $component->params->membersmanager_relation_type))); + } + ); + } + elseif (is_int($relation)) + { + // filter out the components we need + return array_filter( + self::$infoComponents, + function ($component) use ($relation) { + // check if the component is available to this relation + return ($relation == $component->params->membersmanager_relation_type); + } + ); + } + return self::$infoComponents; } - return self::$infoComponents; + return false; } /** @@ -2553,10 +3844,11 @@ abstract class MembersmanagerHelper $listComponents = array_filter( $listComponents, function ($component) { - if (strpos($component->params, 'activate_membersmanager_info') !== false) + if (self::checkJson($component->params) && strpos($component->params, 'activate_membersmanager_info') !== false) { // check if this component is active - return json_decode($component->params)->activate_membersmanager_info; + $component->params = json_decode($component->params); + return $component->params->activate_membersmanager_info; } return false; } @@ -2568,16 +3860,27 @@ abstract class MembersmanagerHelper $lang = JFactory::getLanguage(); foreach ($listComponents as $listComponent) { - // lets do a quick params setup (to objects) - $listComponent->params = json_decode($listComponent->params); - // try to load the translation - $lang->load($listComponent->element, JPATH_ADMINISTRATOR, null, false, true); - // translate the extension name if possible - $listComponent->name = JText::_($listComponent->name); - // translate the info type name - if (isset($listComponent->params->info_type_name)) + if (isset($listComponent->params)) { - $listComponent->params->info_type_name = JText::_(strtoupper($listComponent->element) . '_CONFIG_' . $listComponent->params->info_type_name); + // convert params to object + if (self::checkJson($listComponent->params)) + { + // lets do a quick params setup (to objects) + $listComponent->params = json_decode($listComponent->params); + } + // check that we have an object + if (self::checkObject($listComponent->params)) + { + // try to load the translation + $lang->load($listComponent->element, JPATH_ADMINISTRATOR, null, false, true); + // translate the extension name if possible + $listComponent->name = JText::_($listComponent->name); + // translate the info type name + if (isset($listComponent->params->info_type_name)) + { + $listComponent->params->info_type_name = JText::_(strtoupper($listComponent->element) . '_CONFIG_' . $listComponent->params->info_type_name); + } + } } } return $listComponents; @@ -2595,9 +3898,9 @@ abstract class MembersmanagerHelper /** * Get available assessments based on type */ - public static function getAssessmentAvaillable($type, $account, $multiDimensionalAllowed = true) + public static function getAssessmentAvaillable($types, $account, $multiDimensionalAllowed = true) { - $assessments = self::getAssessmentComponents($type, $account); + $assessments = self::getAssessmentComponents($types, $account); // check if we found components if (self::checkArray($assessments)) { @@ -2625,9 +3928,31 @@ abstract class MembersmanagerHelper if (!isset($bucketAssessments[$assessmentTypeName])) { $bucketAssessments[$assessmentTypeName] = array(); + $bucketAssessments[$assessmentTypeName][] = $component; + } + // check if this is an array set + elseif (self::checkArray($bucketAssessments[$assessmentTypeName])) + { + // set data (one to many) + $bucketAssessments[$assessmentTypeName][] = $component; + } + // check if this is an array set + elseif (self::checkObject($bucketAssessments[$assessmentTypeName])) + { + $bucket_key = $assessmentTypeName . ' *'; + // start array if not already set + if (!isset($bucketAssessments[$bucket_key])) + { + $bucketAssessments[$bucket_key] = array(); + $bucketAssessments[$bucket_key][] = $component; + } + // check if this is an array set + elseif (self::checkArray($bucketAssessments[$bucket_key])) + { + // set data (one to many) + $bucketAssessments[$bucket_key][] = $component; + } } - // set data (one to many) - $bucketAssessments[$assessmentTypeName][] = $component; } } // return the assessment bucket @@ -2636,12 +3961,37 @@ abstract class MembersmanagerHelper return false; } + /** + * Get type assessment component name + */ + public static function getAssessmentComponentName($_component) + { + // see if we have components in memory + if (!self::checkArray(self::$assessmentComponents)) + { + // get list of components + self::$assessmentComponents = self::setAssessmentComponents(); + } + // make sure we have components + if (self::checkArray(self::$assessmentComponents)) + { + foreach (self::$assessmentComponents as $component) + { + if ($component->element === $_component) + { + return $component->name; + } + } + } + return false; + } + /** * Get type assessment names */ - public static function getTypeAssessmentsNames($type, $account, $as = 'string') + public static function getTypeAssessmentsNames($types, $account, $as = 'string') { - $assessments = self::getAssessmentAvaillable($type, $account); + $assessments = self::getAssessmentAvaillable($types, $account); $names = array(); if (self::checkArray($assessments)) { @@ -2670,27 +4020,57 @@ abstract class MembersmanagerHelper /** * Get assessment components */ - public static function getAssessmentComponents($type = null, $account = null) + public static function getAssessmentComponents($types = null, $account = null, $relation = null) { + // see if we have components in memory if (!self::checkArray(self::$assessmentComponents)) { - // get list of Extensions + // get list of components self::$assessmentComponents = self::setAssessmentComponents(); } - // filter by type & account - if ($type && $account && self::checkArray(self::$assessmentComponents)) + // make sure we have components + if (self::checkArray(self::$assessmentComponents)) { - // filter out the components we need - return array_filter( - self::$assessmentComponents, - function ($component) use ($type, $account) { - // check if the component is available to this type of member - return ((isset($component->params->membersmanager_target_type) && in_array($type, (array) $component->params->membersmanager_target_type)) && - (isset($component->params->membersmanager_target_account) && in_array($account, (array) $component->params->membersmanager_target_account))); - } - ); + // convert type json to array + if ($types && self::checkJson($types)) + { + $types = json_decode($types, true); + } + // convert type int to array + if ($types && is_numeric($types) && $types > 0) + { + $types = array($types); + } + // filter by type & account + if ($types && self::checkArray($types) && $account) + { + // our little function to check if two arrays intersect on values + $intersect = function ($a, $b) { $b = array_flip($b); foreach ($a as $v) { if (isset($b[$v])) return true; } return false; }; + // filter out the components we need + return array_filter( + self::$assessmentComponents, + function ($component) use ($types, $account, $relation, $intersect) { + // check if the component is available to this type of member + return ((isset($component->params->membersmanager_target_type) && $intersect($types, (array) $component->params->membersmanager_target_type)) && + (isset($component->params->membersmanager_target_account) && in_array($account, (array) $component->params->membersmanager_target_account)) && + (!$relation || (is_int($relation) && $relation == $component->params->membersmanager_relation_type))); + } + ); + } + elseif (is_int($relation)) + { + // filter out the components we need + return array_filter( + self::$assessmentComponents, + function ($component) use ($relation) { + // check if the component is available to this relation + return ($relation == $component->params->membersmanager_relation_type); + } + ); + } + return self::$assessmentComponents; } - return self::$assessmentComponents; + return false; } /** @@ -2715,10 +4095,11 @@ abstract class MembersmanagerHelper $listComponents = array_filter( $listComponents, function ($component) { - if (strpos($component->params, 'activate_membersmanager_assessment') !== false) + if (self::checkJson($component->params) && strpos($component->params, 'activate_membersmanager_assessment') !== false) { // check if this component is active - return json_decode($component->params)->activate_membersmanager_assessment; + $component->params = json_decode($component->params); + return $component->params->activate_membersmanager_assessment; } return false; } @@ -2730,16 +4111,27 @@ abstract class MembersmanagerHelper $lang = JFactory::getLanguage(); foreach ($listComponents as $listComponent) { - // lets do a quick params setup (to objects) - $listComponent->params = json_decode($listComponent->params); - // try to load the translation - $lang->load($listComponent->element, JPATH_ADMINISTRATOR, null, false, true); - // translate the extension name if possible - $listComponent->name = JText::_($listComponent->name); - // translate the assessment type name - if (isset($listComponent->params->assessment_type_name)) + if (isset($listComponent->params)) { - $listComponent->params->assessment_type_name = JText::_(strtoupper($listComponent->element) . '_CONFIG_' . $listComponent->params->assessment_type_name); + // convert params to object + if (self::checkJson($listComponent->params)) + { + // lets do a quick params setup (to objects) + $listComponent->params = json_decode($listComponent->params); + } + // check that we have an object + if (self::checkObject($listComponent->params)) + { + // try to load the translation + $lang->load($listComponent->element, JPATH_ADMINISTRATOR, null, false, true); + // translate the extension name if possible + $listComponent->name = JText::_($listComponent->name); + // translate the assessment type name + if (isset($listComponent->params->assessment_type_name)) + { + $listComponent->params->assessment_type_name = JText::_(strtoupper($listComponent->element) . '_CONFIG_' . $listComponent->params->assessment_type_name); + } + } } } return $listComponents; @@ -2762,7 +4154,7 @@ abstract class MembersmanagerHelper public static function loadDynamicTabs(&$item, $view = 'member', $return = '') { // only loads if type and account is set - if (is_numeric($item->type) && $item->type > 0 && is_numeric($item->account) && $item->account > 0) + if (isset($item->type) && (self::checkJson($item->type) || (is_numeric($item->type) && $item->type > 0) || self::checkArray($item->type)) && is_numeric($item->account) && $item->account > 0) { // get all the available component calling metods $class = new ReflectionClass('MembersmanagerHelper'); @@ -2775,9 +4167,12 @@ abstract class MembersmanagerHelper return false; } ); + // get the database object + $db = JFactory::getDBO(); // set the tabs $tabs = array(); $layout = array(); + $script = array(); if (self::checkArray($methods)) { foreach ($methods as $method) @@ -2797,7 +4192,12 @@ abstract class MembersmanagerHelper { if (($ids = self::getVars('form', $item->id, $view, 'id', 'IN', str_replace('com_', '', $comp->element))) !== false && self::checkArray($ids)) { - $tables[] = self::getTabLinksTable($ids, $item, $comp, $view, $return); + // load the table + $tables[] = self::getTabLinksTable($ids, $item, $comp, $view, $return, $db); + } + elseif (($tmp = self::getTabLinksTable(null, $item, $comp, $view, $return, $db)) !== false) + { + $tables[] = $tmp; } } // load the tables to the layout @@ -2835,10 +4235,11 @@ abstract class MembersmanagerHelper // check if user are allowed to edit form values or create form values if (($id > 0 && JFactory::getUser()->authorise('form.edit', $component->element . '.form.' . (int) $id)) || ($id == 0 && JFactory::getUser()->authorise('form.create', $component->element))) { - $fields = self::getTabFields($id, $component); + $fields = self::getTabFields($id, $component, $script); // load the fields to the layout if (self::checkString($fields)) { + // add fields $layout[$_name] = $fields; } // add layout to tabs @@ -2853,14 +4254,22 @@ abstract class MembersmanagerHelper } } } - // add layout to tabs + // add remainder layout to tabs if (self::checkArray($layout)) { $tabs[] = self::setTab($layout, $view); } + // add the Relationship tab + self::setRelationshipTab($item, $view, $return, $tabs); // check if we have tabs if (self::checkArray($tabs)) { + // load the script if found + if (self::checkArray($script)) + { + $document = JFactory::getDocument(); + $document->addScriptDeclaration(implode("\n", $script)); + } return implode("\n", $tabs); } } @@ -2868,15 +4277,132 @@ abstract class MembersmanagerHelper } /** - * get the tabe fields + * set the relationship tab * - * @param int $id The item id - * @param object $component The target component details + * @param object $item Data for the form + * @param string $view The view name + * @param string $return The return value if found + * @param array $tabs The exiting tabs array + * + * @return void + * + */ + protected static function setRelationshipTab(&$item, &$view, &$return, &$tabs) + { + // get DB + $db = JFactory::getDBO(); + // check if there is relationships and members in those relationships + if (self::checkObject($item) && isset($item->type) && ($relation_types = self::getRelationshipsByTypes($item->type, $db)) !== false) + { + // get the members already selected relationships + $relation_selected = (isset($item->id) && $item->id > 0) ? self::getRelationshipsByMember($item->id, $db) : false; + // build the fields + $null = null; + $headers = array(); + $form = array(); + foreach ($relation_types as $id => $type) + { + // get the field selection + $selected = ($relation_selected && isset($relation_selected[$id])) ? $relation_selected[$id] : ''; + // set the field note headers + $headers[$id] = self::getRelationshipField($type->name, $type->description, $selected, $null); + // set the field + $form[$id] = self::getRelationshipField($type->name, $type->field_type, $selected, $type->members); + } + // divide the fields in two + $form = self::array_partition($form, 2, true); + // load the field layouts + foreach($form as $key => $fields) + { + $layout[$key] = ''; + foreach ($fields as $pointer => $field) + { + // first set the header + $layout[$key] .= (isset($headers[$pointer])) ? '
' . $headers[$pointer]->label . '
': ''; + // first set the header + $layout[$key] .= '
'; + $layout[$key] .= '
' . $field->label . '
'; + $layout[$key] .= '
' . $field->input . '
'; + $layout[$key] .= '
'; + } + } + // update tabs + $tabs[] = self::setTab($layout, $view, JText::_('COM_MEMBERSMANAGER_RELATIONSHIPS'), 6, false); + } + } + + /** + * get the relationship field + * + * @param string $name The field name + * @param int/string $type The type if int or description if string + * @param array $selected The selected values * * @return string * */ - protected static function getTabFields($id, &$component) + protected static function getRelationshipField(&$name, &$type, &$selected, &$values) + { + switch ($type) + { + case 1: + // build checkboxes + $attributes = array( + 'type' => 'checkboxes', + 'name' => 'relationship_mapping_' . self::safeString($name), + 'label' => $name, + 'class' => 'list_class', + 'description' => 'COM_MEMBERSMANAGER_MAKE_A_SELECTION_TO_CREATE_A_RELATIONSHIP'); + break; + case 2: + // build list + $attributes = array( + 'type' => 'list', + 'name' => 'relationship_mapping_' . self::safeString($name), + 'label' => $name, + 'multiple' => true, + 'class' => 'list_class', + 'description' => 'COM_MEMBERSMANAGER_MAKE_A_SELECTION_TO_CREATE_A_RELATIONSHIP'); + break; + default: + // build a note + $attributes = array( + 'type' => 'note', + 'name' => 'relationship_mapping_note_' . self::safeString($name), + 'label' => $name, + 'class' => 'alert'); + if (self::checkString($type)) + { + $attributes['description'] = $type; + } + break; + } + // set options + $options = null; + if (self::checkArray($values)) + { + // start the building the options + $options = array(); + // load relationship options from array + foreach($values as $value) + { + $options[(int) $value] = self::getMemberName($value); + } + } + return self::getFieldObject($attributes, $selected, $options); + } + + /** + * get the tab fields + * + * @param int $id The item id + * @param object $component The target component details + * @param array $document The document array to load script + * + * @return string + * + */ + protected static function getTabFields($id, &$component, &$document) { // build the rows $rows = ''; @@ -2886,6 +4412,8 @@ abstract class MembersmanagerHelper // get the fields for this form if (($fields = JComponentHelper::getParams($component->element)->get('edit_fields', false)) !== false && self::checkObject($fields)) { + // load the fields script + self::getTabFieldsScript($component->element, $document); // add the id field if the id was found (but hidden) if ($id > 0) { @@ -2905,6 +4433,57 @@ abstract class MembersmanagerHelper return $rows; } + + /** + * get the tab fields script + * + * @param object $component The target component + * @param array $document The document array to load script + * + * @return string + * + */ + protected static function getTabFieldsScript(&$_component, &$document) + { + // get component name + $component = str_replace('com_', '', $_component); + // values to change in script + $replace = array( + 'jform_' => $component . '_', + 'updateFieldRequired' => $component . 'updateFieldRequired', + 'isSet' => $component . 'isSet', + 'vvvvv' => $component . 'uuuu' + ); + // normal path to view javascript file + $script_path = JPATH_ADMINISTRATOR . '/components/' . $_component . '/models/forms/form.js'; + // load the javascript for this view + if (file_exists($script_path) && ($script = self::getFileContents($script_path, false)) !== false) + { + // now update the script and add to document + $document[] = str_replace(array_keys($replace), array_values($replace), $script); + } + // normal path to view file + $view_path = JPATH_ADMINISTRATOR . '/components/' . $_component . '/views/form/tmpl/edit.php'; + // load the javascript form this view + if (file_exists($view_path) && ($w_script = self::getFileContents($view_path, false)) !== false) + { + // get all script from view + $a_script = self::getAllBetween($w_script, ''); + // check if we found any + if (self::checkArray($a_script)) + { + foreach ($a_script as $_script) + { + if (strpos($_script, '// waiting spinner') === false && strpos($_script, 'element); + // get the database columns of this table + $columns = $db->getTableColumns("#__" . $component . "_form", false); // get the global settings $params = JComponentHelper::getParams($comp->element); // get the profile fields @@ -2931,40 +4514,63 @@ abstract class MembersmanagerHelper { $rows[] = '' . $create_button . ''; } - // build the links - foreach ($ids as $id) + // see if id's are found + if (self::checkArray($ids)) { - if (self::checkObject($profile_fields)) + // build the links + foreach ($ids as $id) { - // the bucket - $bucket = array(); - foreach ($profile_fields as $profile) + if (self::checkObject($profile_fields)) { - $bucket[$profile->field] = self::getVar('form', $id, 'id', $profile->field, '=', str_replace('com_', '', $comp->element)); + // the bucket + $bucket = array(); + foreach ($profile_fields as $profile) + { + $bucket[$profile->field] = self::getVar('form', $id, 'id', $profile->field, '=', $component); + } + $rows[] = '' . implode(', ', $bucket) . self::getEditButton($id, 'form', 'forms', $_return, $comp->element) . ''; + } + else + { + // get creating date + $created = self::getVar('form', $id, 'id', 'created', '=', $component); + // set name + $name = self::fancyDayTimeDate($created); + // check if there is a name in table + if (isset($columns['name'])) + { + // get name + $name = self::getVar('form', $id, 'id', 'name', '=', $component) . ' (' . $name . ')'; + } + elseif (isset($columns['title'])) + { + // get name + $name = self::getVar('form', $id, 'id', 'title', '=', $component) . ' (' . $name . ')'; + } + $rows[] = '' . $name . self::getEditButton($id, 'form', 'forms', $_return, $comp->element) . ''; } - $rows[] = '' . implode(', ', $bucket) . self::getEditButton($id, 'form', 'forms', $_return, $comp->element) . ''; - } - else - { - $created = self::getVar('form', $id, 'id', 'created', '=', str_replace('com_', '', $comp->element)); - $rows[] = '' . self::fancyDayTimeDate($created) . self::getEditButton($id, 'form', 'forms', $_return, $comp->element) . ''; } } - // set the header - $head = array($comp->name); - // return the table - return self::setSubformTable($head, $rows, $view . '_' . $comp->name); + // check if we have rows + if (self::checkArray($rows)) + { + // set the header + $head = array($comp->name); + // return the table + return self::setSubformTable($head, $rows, $view . '_' . $comp->name); + } + return false; } /** * get the form fields * - * @param string $layout The layout array - * @param string $code The tab/view code name - * @param string $name The tab name - * @param int $span The span trigger - * @param bool $alert Show the alert + * @param string $layout The layout array + * @param string $code The tab/view code name + * @param string $name The tab name + * @param int $span The span trigger + * @param bool $alert Show the alert * * @return string * @@ -2976,7 +4582,7 @@ abstract class MembersmanagerHelper { $name = implode(' & ', array_keys($layout)); } -$tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); + $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); $tmp .= PHP_EOL . '
'; if (count((array) $layout) == 1) { @@ -3066,7 +4672,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); * @param object $date The main Data * @param string $view The view name * - * @return string + * @return void * */ public static function saveDynamicValues(&$data, $view = 'member') @@ -3083,7 +4689,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } ); // check if we have methods - if (self::checkArray($methods)) + if (self::checkArray($methods) && isset($data['type'], $data['account'])) { // get the app object $app = JFactory::getApplication(); @@ -3208,7 +4814,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); $fieldActive['rules'] = 'rules'; // get the database columns of this table $columns = $db->getTableColumns("#__" . $component . "_form", false); - // no make sure the fields that are not editable are removed (so can't be updated via this form) + // now make sure the fields that are not editable are removed (so can't be updated via this form) foreach(array_keys($columns) as $field) { if (!isset($fieldActive[$field])) @@ -3259,8 +4865,251 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } } + /** - * Load the Component xml manifest. + * save the relationships + * + * @param object $date The main Data + * + * @return void + * + */ + public static function saveRelationships(&$data) + { + // get the app object + $app = JFactory::getApplication(); + // get the user object + $user = JFactory::getUser(); + // check if user may edit + if (0) // !$user->authorise('member.edit.type', 'com_membersmanager.member.' . (int) $data['id'])) (TODO) + { + $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_THIS_MEMBER_RELATIONSHIPS_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR'), 'warning'); + return; + } + // check if there is relationships and members in those relationships + if (self::checkArray($data) && isset($data['id']) && is_numeric($data['id']) && $data['id'] > 0 && isset($data['type']) + && ($relation_types = self::getRelationshipsByTypes($data['type'], $db, true)) !== false) + { + // get database object + $db = JFactory::getDbo(); + // get the post object + $post = JFactory::getApplication()->input->post; + // Create a new query object. + $query = $db->getQuery(true); + // build insert query + $query->insert($db->quoteName('#__membersmanager_relation_map')); + // Insert columns. + $columns = array('relation', 'member', 'type'); + $query->columns($db->quoteName($columns)); + // found values + $found = false; + // start looping the methods + foreach ($relation_types as $type) + { + // delete all previous set relationships of this member and type + self::deleteRelationship($data['id'], $type->id, $db); + // get components + $get = 'relationship_mapping_' . self::safeString($type->name); + // get the posted date if there were any + $_values = $post->get($get, array(), 'array'); + // check if we found relationships + if (self::checkArray($_values)) + { + // build the values + foreach ($_values as $_value) + { + if (is_numeric($_value) && $_value > 0) + { + $query->values((int) $_value . ',' . (int) $data['id'] . ',' . (int) $type->id); + } + } + $found = true; + } + } + // save relationship if found + if ($found) + { + // Set the query using our newly populated query object and execute it. + $db->setQuery($query); + $db->execute(); + } + } + } + + /** + * delete the relationships + * + * @param int $member The member ID + * @param int $type The type ID + * + * @return void + * + */ + public static function deleteRelationship(&$member, &$type, &$db) + { + $query = $db->getQuery(true); + // delete all types the are linked to this member + $conditions = array( + $db->quoteName('member') . ' = ' . (int) $member, + $db->quoteName('type') . ' = ' . (int) $type + ); + $query->delete($db->quoteName('#__membersmanager_relation_map')); + $query->where($conditions); + $db->setQuery($query); + $db->execute(); + } + + + /** + * update the type map, for quick search + * + * @param int $member The member ID + * @param string/array $types The types + * + * @return void + * + */ + public static function updateTypes(&$member, $types = null) + { + // get the app object + $app = JFactory::getApplication(); + // get the user object + $user = JFactory::getUser(); + // check if user may edit + if (!$user->authorise('member.edit.type', 'com_membersmanager.member.' . (int) $member)) + { + $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_THIS_MEMBER_TYPE_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR'), 'warning'); + return; + } + // get database object + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + // delete all types the are linked to this member + $conditions = array( + $db->quoteName('member') . ' = ' . (int) $member + ); + $query->delete($db->quoteName('#__membersmanager_type_map')); + $query->where($conditions); + $db->setQuery($query); + $db->execute(); + // now set the new values + if (self::checkArray($types)) + { + // Create a new query object. + $query = $db->getQuery(true); + // Insert columns. + $columns = array('member', 'type'); + // build insert query + $query->insert($db->quoteName('#__membersmanager_type_map')); + $query->columns($db->quoteName($columns)); + // build the values + foreach ($types as $type) + { + $query->values((int) $member . ',' . (int) $type); + } + // Set the query using our newly populated query object and execute it. + $db->setQuery($query); + $db->execute(); + } + } + + + /** + * Array Partitioning Function + * + * @link http://php.net/manual/en/function.array-chunk.php#75022 + * Thanks to azspot at gmail dot com + * + * @param array $array

+ * The array to work on + *

+ * @param int $size

+ * The size of each chunk + *

+ * @param bool $preserve_keys [optional]

+ * When set to TRUE keys will be preserved. + * Default is FALSE which will reindex the chunk numerically + *

+ * + * @return array a multidimensional numerically indexed array, starting with zero, + * with each dimension containing size elements. + */ + public static function array_partition($array, $size, $preserve_keys = FALSE) + { + // set some key values + $arraylen = count((array) $array ); + $partlen = floor( $arraylen / $size ); + $partrem = $arraylen % $size; + // start the partition builder + $partition = array(); + $offset = 0; + for ($sizex = 0; $sizex < $size; $sizex++) + { + // get the partition length + $length = ($sizex < $partrem) ? $partlen + 1 : $partlen; + // set the partition values + $partition[$sizex] = array_slice($array, $offset, $length, $preserve_keys); + // update the offset + $offset += $length; + } + return $partition; + } + + + /** + * get the content of a file + * + * @param string $path The path to the file + * @param string/bool $none The return value if no content was found + * + * @return string On success + * + */ + public static function getFileContents($path, $none = '') + { + if (self::checkString($path)) + { + // use basic file get content for now + if (($content = @file_get_contents($path)) !== FALSE) + { + return $content; + } + // use curl if available + elseif (function_exists('curl_version')) + { + // start curl + $ch = curl_init(); + // set the options + $options = array(); + $options[CURLOPT_URL] = $path; + $options[CURLOPT_USERAGENT] = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; + $options[CURLOPT_RETURNTRANSFER] = TRUE; + $options[CURLOPT_SSL_VERIFYPEER] = FALSE; + // load the options + curl_setopt_array($ch, $options); + // get the content + $content = curl_exec($ch); + // close the connection + curl_close($ch); + // return if found + if (self::checkString($content)) + { + return $content; + } + } + elseif (property_exists('MembersmanagerHelper', 'curlErrorLoaded') && !self::$curlErrorLoaded) + { + // set the notice + JFactory::getApplication()->enqueueMessage(JText::_('COM_MEMBERSMANAGER_HTWOCURL_NOT_FOUNDHTWOPPLEASE_SETUP_CURL_ON_YOUR_SYSTEM_OR_BMEMBERSMANAGERB_WILL_NOT_FUNCTION_CORRECTLYP'), 'Error'); + // load this notice only once + self::$curlErrorLoaded = true; + } + } + return $none; + } + + /** + * Load the Component xml manifest. **/ public static function manifest() { @@ -3269,12 +5118,12 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Joomla version object + * Joomla version object **/ protected static $JVersion; /** - * set/get Joomla version + * set/get Joomla version **/ public static function jVersion() { @@ -3287,7 +5136,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Load the Contributors details. + * Load the Contributors details. **/ public static function getContributors() { @@ -3333,14 +5182,27 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Configure the Linkbar. + * Configure the Linkbar. **/ public static function addSubmenu($submenu) { // load user for access menus $user = JFactory::getUser(); // load the submenus to sidebar - + + if ($user->authorise('member.access', 'com_membersmanager') && $user->authorise('member.submenu', 'com_membersmanager')) + { + JHtmlSidebar::addEntry(JText::_('COM_MEMBERSMANAGER_SUBMENU_MEMBERS'), 'index.php?option=com_membersmanager&view=members', $submenu === 'members'); + } + if (JComponentHelper::isEnabled('com_fields')) + { + JHtmlSidebar::addEntry(JText::_('COM_MEMBERSMANAGER_SUBMENU_MEMBERS_FIELDS'), 'index.php?option=com_fields&context=com_membersmanager.member', $submenu === 'fields.fields'); + JHtmlSidebar::addEntry(JText::_('COM_MEMBERSMANAGER_SUBMENU_MEMBERS_FIELDS_GROUPS'), 'index.php?option=com_fields&view=groups&context=com_membersmanager.member', $submenu === 'fields.groups'); + } + if ($user->authorise('type.access', 'com_membersmanager') && $user->authorise('type.submenu', 'com_membersmanager')) + { + JHtmlSidebar::addEntry(JText::_('COM_MEMBERSMANAGER_SUBMENU_TYPES'), 'index.php?option=com_membersmanager&view=types', $submenu === 'types'); + } } /** @@ -4154,7 +6016,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Get any component's model + * Get any component's model **/ public static function getModel($name, $path = JPATH_COMPONENT_ADMINISTRATOR, $component = 'Membersmanager', $config = array()) { @@ -4198,9 +6060,9 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Add to asset Table + * Add to asset Table */ - public static function setAsset($id,$table) + public static function setAsset($id, $table, $inherit = true) { $parent = JTable::getInstance('Asset'); $parent->loadByName('com_membersmanager'); @@ -4232,7 +6094,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); $asset->name = $name; $asset->title = $title; // get the default asset rules - $rules = self::getDefaultAssetRules('com_membersmanager',$table); + $rules = self::getDefaultAssetRules('com_membersmanager', $table, $inherit); if ($rules instanceof JAccessRules) { $asset->rules = (string) $rules; @@ -4260,55 +6122,62 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Gets the default asset Rules for a component/view. + * Gets the default asset Rules for a component/view. */ - protected static function getDefaultAssetRules($component,$view) + protected static function getDefaultAssetRules($component, $view, $inherit = true) { - // Need to find the asset id by the name of the component. - $db = JFactory::getDbo(); - $query = $db->getQuery(true) - ->select($db->quoteName('id')) - ->from($db->quoteName('#__assets')) - ->where($db->quoteName('name') . ' = ' . $db->quote($component)); - $db->setQuery($query); - $db->execute(); - if ($db->loadRowList()) + // if new or inherited + $assetId = 0; + // Only get the actual item rules if not inheriting + if (!$inherit) { - // asset alread set so use saved rules - $assetId = (int) $db->loadResult(); - $result = JAccess::getAssetRules($assetId); - if ($result instanceof JAccessRules) + // Need to find the asset id by the name of the component. + $db = JFactory::getDbo(); + $query = $db->getQuery(true) + ->select($db->quoteName('id')) + ->from($db->quoteName('#__assets')) + ->where($db->quoteName('name') . ' = ' . $db->quote($component)); + $db->setQuery($query); + $db->execute(); + // check that there is a value + if ($db->getNumRows()) { - $_result = (string) $result; - $_result = json_decode($_result); - foreach ($_result as $name => &$rule) - { - $v = explode('.', $name); - if ($view !== $v[0]) - { - // remove since it is not part of this view - unset($_result->$name); - } - else - { - // clear the value since we inherit - $rule = array(); - } - } - // check if there are any view values remaining - if (count((array)$_result)) - { - $_result = json_encode($_result); - $_result = array($_result); - // Instantiate and return the JAccessRules object for the asset rules. - $rules = new JAccessRules($_result); - - return $rules; - } - return $result; + // asset already set so use saved rules + $assetId = (int) $db->loadResult(); } } - return JAccess::getAssetRules(0); + // get asset rules + $result = JAccess::getAssetRules($assetId); + if ($result instanceof JAccessRules) + { + $_result = (string) $result; + $_result = json_decode($_result); + foreach ($_result as $name => &$rule) + { + $v = explode('.', $name); + if ($view !== $v[0]) + { + // remove since it is not part of this view + unset($_result->$name); + } + elseif ($inherit) + { + // clear the value since we inherit + $rule = array(); + } + } + // check if there are any view values remaining + if (count($_result)) + { + $_result = json_encode($_result); + $_result = array($_result); + // Instantiate and return the JAccessRules object for the asset rules. + $rules = new JAccessRules($_result); + // return filtered rules + return $rules; + } + } + return $result; } /** @@ -4477,11 +6346,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Check if have an json string + * Check if have an json string * - * @input string The json string to check + * @input string The json string to check * - * @returns bool true on success + * @returns bool true on success **/ public static function checkJson($string) { @@ -4494,11 +6363,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Check if have an object with a length + * Check if have an object with a length * - * @input object The object to check + * @input object The object to check * - * @returns bool true on success + * @returns bool true on success **/ public static function checkObject($object) { @@ -4510,15 +6379,15 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Check if have an array with a length + * Check if have an array with a length * - * @input array The array to check + * @input array The array to check * - * @returns bool true on success + * @returns bool/int number of items in array on success **/ public static function checkArray($array, $removeEmptyString = false) { - if (isset($array) && is_array($array) && count((array)$array) > 0) + if (isset($array) && is_array($array) && ($nr = count((array)$array)) > 0) { // also make sure the empty strings are removed if ($removeEmptyString) @@ -4532,17 +6401,17 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } return self::checkArray($array, false); } - return true; + return $nr; } return false; } /** - * Check if have a string with a length + * Check if have a string with a length * - * @input string The string to check + * @input string The string to check * - * @returns bool true on success + * @returns bool true on success **/ public static function checkString($string) { @@ -4554,10 +6423,10 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Check if we are connected - * Thanks https://stackoverflow.com/a/4860432/1429677 + * Check if we are connected + * Thanks https://stackoverflow.com/a/4860432/1429677 * - * @returns bool true on success + * @returns bool true on success **/ public static function isConnected() { @@ -4579,11 +6448,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Merge an array of array's + * Merge an array of array's * - * @input array The arrays you would like to merge + * @input array The arrays you would like to merge * - * @returns array on success + * @returns array on success **/ public static function mergeArrays($arrays) { @@ -4609,11 +6478,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Shorten a string + * Shorten a string * - * @input string The you would like to shorten + * @input string The you would like to shorten * - * @returns string on success + * @returns string on success **/ public static function shorten($string, $length = 40, $addTip = true) { @@ -4650,11 +6519,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Making strings safe (various ways) + * Making strings safe (various ways) * - * @input string The you would like to make safe + * @input string The you would like to make safe * - * @returns string on success + * @returns string on success **/ public static function safeString($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true) { @@ -4794,11 +6663,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Convert an integer into an English word string - * Thanks to Tom Nicholson + * Convert an integer into an English word string + * Thanks to Tom Nicholson * - * @input an int - * @returns a string + * @input an int + * @returns a string **/ public static function numberToString($x) { @@ -4885,9 +6754,9 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Random Key + * Random Key * - * @returns a string + * @returns a string **/ public static function randomkey($size) { diff --git a/admin/language/en-GB/en-GB.com_membersmanager.ini b/admin/language/en-GB/en-GB.com_membersmanager.ini index e1db5b4..963a387 100644 --- a/admin/language/en-GB/en-GB.com_membersmanager.ini +++ b/admin/language/en-GB/en-GB.com_membersmanager.ini @@ -15,6 +15,14 @@ COM_MEMBERSMANAGER_CONFIG_AUTHOR_EMAIL_LABEL="Author Email" COM_MEMBERSMANAGER_CONFIG_AUTHOR_NAME_DESC="The name of the author of this component." COM_MEMBERSMANAGER_CONFIG_AUTHOR_NAME_LABEL="Author Name" COM_MEMBERSMANAGER_CONFIG_AUTO_LOAD="Auto" +COM_MEMBERSMANAGER_CONFIG_BUTTON_FORMS_NAME_DESCRIPTION="What would like to name the forms button." +COM_MEMBERSMANAGER_CONFIG_BUTTON_FORMS_NAME_HINT="Forms" +COM_MEMBERSMANAGER_CONFIG_BUTTON_FORMS_NAME_LABEL="Forms Button Name" +COM_MEMBERSMANAGER_CONFIG_BUTTON_FORMS_NAME_MESSAGE="Error! Please add some forms button name here." +COM_MEMBERSMANAGER_CONFIG_BUTTON_REPORT_NAME_DESCRIPTION="What would like to name the report button." +COM_MEMBERSMANAGER_CONFIG_BUTTON_REPORT_NAME_HINT="Report" +COM_MEMBERSMANAGER_CONFIG_BUTTON_REPORT_NAME_LABEL="Report Button Name" +COM_MEMBERSMANAGER_CONFIG_BUTTON_REPORT_NAME_MESSAGE="Error! Please add some report button name here." COM_MEMBERSMANAGER_CONFIG_CHECK_TIMER_DESC="Set the intervals for the auto checkin fuction of tables that checks out the items to an user." COM_MEMBERSMANAGER_CONFIG_CHECK_TIMER_LABEL="Check in timer" COM_MEMBERSMANAGER_CONFIG_CHECK_TIMER_OPTION_FIVE="Once a week" @@ -34,6 +42,11 @@ COM_MEMBERSMANAGER_CONFIG_COMPANYNAME_HINT="Company Name Here" COM_MEMBERSMANAGER_CONFIG_COMPANYNAME_LABEL="Company Name" COM_MEMBERSMANAGER_CONFIG_COMPANYNAME_MESSAGE="Error! Please add company name here." COM_MEMBERSMANAGER_CONFIG_COMPANY_DETAILS="Company Details" +COM_MEMBERSMANAGER_CONFIG_COMPONENT="Component" +COM_MEMBERSMANAGER_CONFIG_COMPONENTS_DESCRIPTION="Select the related components" +COM_MEMBERSMANAGER_CONFIG_COMPONENTS_LABEL="Components (one to one)" +COM_MEMBERSMANAGER_CONFIG_COMPONENT_DESCRIPTION="Select the related component" +COM_MEMBERSMANAGER_CONFIG_COMPONENT_LABEL="Component" COM_MEMBERSMANAGER_CONFIG_COUNTRY_DESCRIPTION="Country Name" COM_MEMBERSMANAGER_CONFIG_COUNTRY_HINT="Namibia" COM_MEMBERSMANAGER_CONFIG_COUNTRY_LABEL="Country" @@ -71,18 +84,147 @@ COM_MEMBERSMANAGER_CONFIG_GLOBAL_LABEL="Global" COM_MEMBERSMANAGER_CONFIG_GRADIANT_LOAD="Gradient" COM_MEMBERSMANAGER_CONFIG_IMAGE_FORMATS_DESCRIPTION="Select all the image formats allowed" COM_MEMBERSMANAGER_CONFIG_IMAGE_FORMATS_LABEL="Allowed Images Formats" +COM_MEMBERSMANAGER_CONFIG_ITEM_TEMPLATE_DESCRIPTION="Set the HTML for each item" +COM_MEMBERSMANAGER_CONFIG_ITEM_TEMPLATE_HINT="html for an item" +COM_MEMBERSMANAGER_CONFIG_ITEM_TEMPLATE_LABEL="Item Template" COM_MEMBERSMANAGER_CONFIG_JPEG=".jpeg" COM_MEMBERSMANAGER_CONFIG_JPG=".jpg" +COM_MEMBERSMANAGER_CONFIG_LIST="List" +COM_MEMBERSMANAGER_CONFIG_LIST_ITEM_TEMPLATE_DESCRIPTION="Set the HTML for a single list item" +COM_MEMBERSMANAGER_CONFIG_LIST_ITEM_TEMPLATE_HINT="// html for single list item +
  • [member_name]
  • " +COM_MEMBERSMANAGER_CONFIG_LIST_ITEM_TEMPLATE_LABEL="List Item Template" +COM_MEMBERSMANAGER_CONFIG_LIST_TEMPLATE_DESCRIPTION="Set the HTML for the list surrounding the list items - to add items (all list items) use [load_items] placeholder" +COM_MEMBERSMANAGER_CONFIG_LIST_TEMPLATE_HINT="// html for the body surrounding the items +
      + [load_items] +
    " +COM_MEMBERSMANAGER_CONFIG_LIST_TEMPLATE_LABEL="List Template" +COM_MEMBERSMANAGER_CONFIG_MAIN="Main" +COM_MEMBERSMANAGER_CONFIG_MAIN_LOGIN="Main & Login" +COM_MEMBERSMANAGER_CONFIG_MAIN_TEMPLATE_DESCRIPTION="Set the HTML for the main template" +COM_MEMBERSMANAGER_CONFIG_MAIN_TEMPLATE_HINT="html for the main template - items placeholder is [load_items]" +COM_MEMBERSMANAGER_CONFIG_MAIN_TEMPLATE_LABEL="Main Template" +COM_MEMBERSMANAGER_CONFIG_MANY_COMPONENTS_DESCRIPTION="Select the components that has a one to many relationship with these members." +COM_MEMBERSMANAGER_CONFIG_MANY_COMPONENTS_LABEL="Components (one to many)" COM_MEMBERSMANAGER_CONFIG_MEDIUM_KEY_DESC="Set the full path to where the key file must be stored. Make sure it is behind the root folder of your website, so that it is not public accessible." COM_MEMBERSMANAGER_CONFIG_MEDIUM_KEY_LABEL="Medium Key (Path)" COM_MEMBERSMANAGER_CONFIG_MEDIUM_KEY_NOTE_DESC="When using the medium encryption option, the system generates its own key and stores it in a file at the folder/path you set here.
    Never change this key once it is set, or remove the key file! DATA WILL GET CORRUPTED IF YOU DO! Also make sure the full path to where the the key file should be stored, is behind the root folder of your website/system, so that it is not public accessible. Making a backup of this key file over a secure connection is recommended!" COM_MEMBERSMANAGER_CONFIG_MEDIUM_KEY_NOTE_LABEL="Medium Encryption" COM_MEMBERSMANAGER_CONFIG_MEDIUM_KEY_PATH_ERROR="Medium key path (for encryption of various fields) does not exist, or is not writable. Please check the path and update it in the global option of this component." +COM_MEMBERSMANAGER_CONFIG_MEMBERS="Members" +COM_MEMBERSMANAGER_CONFIG_MEMBERS_DISPLAY_TYPE_DESCRIPTION="Set the display type for the members" +COM_MEMBERSMANAGER_CONFIG_MEMBERS_DISPLAY_TYPE_LABEL="Members Display Type" COM_MEMBERSMANAGER_CONFIG_MOBILE_PHONE_DESCRIPTION="Enter Mobile Phone Number" COM_MEMBERSMANAGER_CONFIG_MOBILE_PHONE_HINT="Mobile Phone Here" COM_MEMBERSMANAGER_CONFIG_MOBILE_PHONE_LABEL="Mobile Phone" COM_MEMBERSMANAGER_CONFIG_MOBILE_PHONE_MESSAGE="Error! Please add mobile phone number here." COM_MEMBERSMANAGER_CONFIG_NO="No" +COM_MEMBERSMANAGER_CONFIG_NOTE_CORE_MEMBER_PLACEHOLDERS_DESCRIPTION=" +
    Loading placeholders.
    +" +COM_MEMBERSMANAGER_CONFIG_NOTE_CORE_MEMBER_PLACEHOLDERS_LABEL="Core Member Placeholders" COM_MEMBERSMANAGER_CONFIG_NOTE_DOCUMENT_PLACEHOLDERS_DESCRIPTION="
    Loading placeholders.
    " COM_MEMBERSMANAGER_CONFIG_NOTE_DOCUMENT_PLACEHOLDERS_LABEL="Document Placeholders" COM_MEMBERSMANAGER_CONFIG_ONLY_EXTRA="Only Extra" +COM_MEMBERSMANAGER_CONFIG_PANELS="Panels" +COM_MEMBERSMANAGER_CONFIG_PANELS_TEMPLATE_DESCRIPTION="Set the HTML for the body (surrounding the panels) - to add items (all panels) use [load_items] placeholder" +COM_MEMBERSMANAGER_CONFIG_PANELS_TEMPLATE_HINT="// html for the body surrounding the panels (items) +
    + [load_items] +
    " +COM_MEMBERSMANAGER_CONFIG_PANELS_TEMPLATE_LABEL="Panels Template" +COM_MEMBERSMANAGER_CONFIG_PANEL_TEMPLATE_DESCRIPTION="Set the HTML for a single panel" +COM_MEMBERSMANAGER_CONFIG_PANEL_TEMPLATE_HINT="// html for a single panel +
    [member_name]
    " +COM_MEMBERSMANAGER_CONFIG_PANEL_TEMPLATE_LABEL="Panel Template" COM_MEMBERSMANAGER_CONFIG_PHONE_DESCRIPTION="The phone number of the contact person." COM_MEMBERSMANAGER_CONFIG_PHONE_HINT="Phone Number Here!" COM_MEMBERSMANAGER_CONFIG_PHONE_LABEL="Phone Number" COM_MEMBERSMANAGER_CONFIG_PHONE_MESSAGE="Error! Please add phone number here." +COM_MEMBERSMANAGER_CONFIG_PLACEHOLDER_DESCRIPTION="to use in main template " +COM_MEMBERSMANAGER_CONFIG_PLACEHOLDER_HINT="component_name_1" +COM_MEMBERSMANAGER_CONFIG_PLACEHOLDER_LABEL="Unique Placeholder" +COM_MEMBERSMANAGER_CONFIG_PLACEHOLDER_PREFIX_DESCRIPTION="What would like to use as the prefix of the values when used in templates." +COM_MEMBERSMANAGER_CONFIG_PLACEHOLDER_PREFIX_HINT="member" +COM_MEMBERSMANAGER_CONFIG_PLACEHOLDER_PREFIX_LABEL="Placeholder Prefix" +COM_MEMBERSMANAGER_CONFIG_PLACEHOLDER_PREFIX_MESSAGE="Error! Please add some placeholder prefix here." COM_MEMBERSMANAGER_CONFIG_PNG=".png" COM_MEMBERSMANAGER_CONFIG_POSTALCODE_DESCRIPTION="Please add your postal code here" COM_MEMBERSMANAGER_CONFIG_POSTALCODE_HINT="9000" @@ -154,6 +314,9 @@ COM_MEMBERSMANAGER_CONFIG_PROFILE_HEIGHT_LABEL="Profile Height (in pixels)" COM_MEMBERSMANAGER_CONFIG_PROFILE_WIDTH_HINT="Only Numbers" COM_MEMBERSMANAGER_CONFIG_PROFILE_WIDTH_LABEL="Profile Width (in pixels)" COM_MEMBERSMANAGER_CONFIG_PUBLIC_DETAILS_NOTE_DESCRIPTION="Your Public Contact Details" +COM_MEMBERSMANAGER_CONFIG_QTY_DESCRIPTION="0 is all" +COM_MEMBERSMANAGER_CONFIG_QTY_HINT="qty" +COM_MEMBERSMANAGER_CONFIG_QTY_LABEL="Qty" COM_MEMBERSMANAGER_CONFIG_REGION_DESCRIPTION="Please add your region or state name here" COM_MEMBERSMANAGER_CONFIG_REGION_HINT="Region Name" COM_MEMBERSMANAGER_CONFIG_REGION_LABEL="Region/State" @@ -162,6 +325,29 @@ COM_MEMBERSMANAGER_CONFIG_STREET_DESCRIPTION="Please add your street address her COM_MEMBERSMANAGER_CONFIG_STREET_HINT="16 Street Name" COM_MEMBERSMANAGER_CONFIG_STREET_LABEL="Street Address" COM_MEMBERSMANAGER_CONFIG_STREET_MESSAGE="Error! Please add street here." +COM_MEMBERSMANAGER_CONFIG_SUB="Sub" +COM_MEMBERSMANAGER_CONFIG_SUB_LOGIN="Sub & Login" +COM_MEMBERSMANAGER_CONFIG_TABLE="Table" +COM_MEMBERSMANAGER_CONFIG_TABLE_ROW_TEMPLATE_DESCRIPTION="Set the HTML for a single row" +COM_MEMBERSMANAGER_CONFIG_TABLE_ROW_TEMPLATE_HINT="// html for a single row + +[member_name] +[member_email] + +" +COM_MEMBERSMANAGER_CONFIG_TABLE_ROW_TEMPLATE_LABEL="Table Row Template" +COM_MEMBERSMANAGER_CONFIG_TABLE_TEMPLATE_DESCRIPTION="Set the HTML for the table surrounding the rows - to add items (all rows) use [load_items] placeholder" +COM_MEMBERSMANAGER_CONFIG_TABLE_TEMPLATE_HINT="// html for the table surrounding the rows (items) + + + [load_items] + +
    " +COM_MEMBERSMANAGER_CONFIG_TABLE_TEMPLATE_LABEL="Table Template" +COM_MEMBERSMANAGER_CONFIG_TARGET_ACCOUNT_DESCRIPTION="What type of Accounts should we get." +COM_MEMBERSMANAGER_CONFIG_TARGET_ACCOUNT_LABEL="Targeted Accounts" +COM_MEMBERSMANAGER_CONFIG_TARGET_TYPE_DESCRIPTION="Select the types of members you would like to load." +COM_MEMBERSMANAGER_CONFIG_TARGET_TYPE_LABEL="Target Member Types" COM_MEMBERSMANAGER_CONFIG_UIKIT_DESC="The Parameters for the uikit are set here.
    Uikit is a lightweight and modular front-end framework for developing fast and powerful web interfaces. For more info visit version 2 or version 3" COM_MEMBERSMANAGER_CONFIG_UIKIT_LABEL="Uikit2 and Uikit3 Settings" @@ -185,7 +371,6 @@ COM_MEMBERSMANAGER_CONTRIBUTORS="Contributors" COM_MEMBERSMANAGER_COULD_NOT_UPLOAD_THE_FILE="Could not upload the file!" COM_MEMBERSMANAGER_CPANEL_ACCESS_SITE="cPanel (Site) Access" COM_MEMBERSMANAGER_CPANEL_ACCESS_SITE_DESC=" Allows the users in this group to access site cpanel." -COM_MEMBERSMANAGER_CREATE_A_REGION="create a region" COM_MEMBERSMANAGER_CREATE_NEW_S="Create New %s" COM_MEMBERSMANAGER_DASH="Dashboard" COM_MEMBERSMANAGER_DASHBOARD="Members Manager Dashboard" @@ -205,6 +390,8 @@ COM_MEMBERSMANAGER_EXPORT_DATA_DESC=" Allows users in this group to export data. COM_MEMBERSMANAGER_EXPORT_FAILED="Export Failed" COM_MEMBERSMANAGER_GREAT_SS_IS_AVAILABLE="Great, %s(%s) is available!" COM_MEMBERSMANAGER_HELP_MANAGER="Help" +COM_MEMBERSMANAGER_HTWOCURL_NOT_FOUNDHTWOPPLEASE_SETUP_CURL_ON_YOUR_SYSTEM_OR_BMEMBERSMANAGERB_WILL_NOT_FUNCTION_CORRECTLYP="

    Curl Not Found!

    Please setup curl on your system, or membersmanager will not function correctly!

    " +COM_MEMBERSMANAGER_IMAGE="Image" COM_MEMBERSMANAGER_IMPORT_CONTINUE="Continue" COM_MEMBERSMANAGER_IMPORT_DATA="Import Data" COM_MEMBERSMANAGER_IMPORT_DATA_DESC=" Allows users in this group to import data." @@ -243,11 +430,13 @@ COM_MEMBERSMANAGER_IMPORT_UNABLE_TO_FIND_IMPORT_PACKAGE="Package to import not f COM_MEMBERSMANAGER_IMPORT_UPDATE_DATA="Import Data" COM_MEMBERSMANAGER_IMPORT_UPLOAD_BOTTON="Upload File" COM_MEMBERSMANAGER_INACTIVE="Inactive" +COM_MEMBERSMANAGER_INFO="Info" COM_MEMBERSMANAGER_KEEP_ORIGINAL_ACCESS="- Keep Original Access -" COM_MEMBERSMANAGER_KEEP_ORIGINAL_CATEGORY="- Keep Original Category -" COM_MEMBERSMANAGER_KEEP_ORIGINAL_STATE="- Keep Original State -" COM_MEMBERSMANAGER_LICENSE="License" COM_MEMBERSMANAGER_MAIN_MEMBER="Main Member" +COM_MEMBERSMANAGER_MAKE_A_SELECTION_TO_CREATE_A_RELATIONSHIP="Make a selection to create a relationship." COM_MEMBERSMANAGER_MEMBER="Member" COM_MEMBERSMANAGER_MEMBERS="Members" COM_MEMBERSMANAGER_MEMBERS_ACCESS="Members Access" @@ -260,6 +449,8 @@ COM_MEMBERSMANAGER_MEMBERS_ACCESS_PASSWORD_CHECK_DESC="Allows the users in this COM_MEMBERSMANAGER_MEMBERS_ACCESS_PASSWORD_DESC="Allows the users in this group to access password of member" COM_MEMBERSMANAGER_MEMBERS_ACCESS_PROFILE_IMAGE="Members Access Profile Image" COM_MEMBERSMANAGER_MEMBERS_ACCESS_PROFILE_IMAGE_DESC="Allows the users in this group to access profile image of member" +COM_MEMBERSMANAGER_MEMBERS_ACCESS_SITE="Members (Site) Access" +COM_MEMBERSMANAGER_MEMBERS_ACCESS_SITE_DESC=" Allows the users in this group to access site members." COM_MEMBERSMANAGER_MEMBERS_ACCESS_USEREMAIL="Members Access Useremail" COM_MEMBERSMANAGER_MEMBERS_ACCESS_USEREMAIL_DESC="Allows the users in this group to access useremail of member" COM_MEMBERSMANAGER_MEMBERS_ACCESS_USERNAME="Members Access Username" @@ -332,6 +523,8 @@ COM_MEMBERSMANAGER_MEMBERS_N_ITEMS_UNFEATURED="%s Members unfeatured." COM_MEMBERSMANAGER_MEMBERS_N_ITEMS_UNFEATURED_1="%s Member unfeatured." COM_MEMBERSMANAGER_MEMBERS_N_ITEMS_UNPUBLISHED="%s Members unpublished." COM_MEMBERSMANAGER_MEMBERS_N_ITEMS_UNPUBLISHED_1="%s Member unpublished." +COM_MEMBERSMANAGER_MEMBERS_SUBMENU="Members Submenu" +COM_MEMBERSMANAGER_MEMBERS_SUBMENU_DESC="Allows the users in this group to submenu of member" COM_MEMBERSMANAGER_MEMBERS_VIEW_ACCOUNT="Members View Account" COM_MEMBERSMANAGER_MEMBERS_VIEW_ACCOUNT_DESC="Allows the users in this group to view account of member" COM_MEMBERSMANAGER_MEMBERS_VIEW_EMAIL="Members View Email" @@ -465,20 +658,25 @@ COM_MEMBERSMANAGER_NEW="New" COM_MEMBERSMANAGER_NOT_FOUND_OR_ACCESS_DENIED="Not found or access denied!" COM_MEMBERSMANAGER_NO_ACCESS_GRANTED="No Access Granted!" COM_MEMBERSMANAGER_NO_IMPORT_FILE_SELECTED="No import file selected." -COM_MEMBERSMANAGER_NO_NAME="No Name" -COM_MEMBERSMANAGER_NO_PLACEHOLDERS_WERE_FOUND_PLEASE_TRY_AGAIN_LATER="No placeholders were found, please try again later." COM_MEMBERSMANAGER_NO_TEMPLATE_FOR_BSB_WERE_FOUND="No template for %s were found" COM_MEMBERSMANAGER_OR="or" +COM_MEMBERSMANAGER_PLACEHOLDERS_NOT_FOUND="Placeholders not found" COM_MEMBERSMANAGER_PRINT="Print" COM_MEMBERSMANAGER_PROPORTIONALLY="proportionally" COM_MEMBERSMANAGER_PUBLISHED="Published" +COM_MEMBERSMANAGER_RELATIONSHIPS="Relationships" COM_MEMBERSMANAGER_REMOVE="Remove" COM_MEMBERSMANAGER_SAVE_SUCCESS="Great! Item successfully saved." COM_MEMBERSMANAGER_SAVE_WARNING="The value already existed so please select another." -COM_MEMBERSMANAGER_SELECT_A_REGION="select a region" +COM_MEMBERSMANAGER_SELECT_AN_OPTION="Select an option" +COM_MEMBERSMANAGER_SUBMENU_MEMBERS="Members" +COM_MEMBERSMANAGER_SUBMENU_MEMBERS_FIELDS="Members Fields" +COM_MEMBERSMANAGER_SUBMENU_MEMBERS_FIELDS_GROUPS="Members Field Groups" +COM_MEMBERSMANAGER_SUBMENU_TYPES="Types" COM_MEMBERSMANAGER_S_COULD_NOT_BE_SAVED_PLEASE_TRY_AGAIN_THIS_COULD_BE_DUE_TO_THE_FACT_THIS_THE_MEMBER_ID_WAS_NOT_READY="%s could not be saved, please try again. This could be due to the fact this the member ID was not ready." COM_MEMBERSMANAGER_S_DATA_COULD_NOT_BE_SAVED="%s data could not be saved" COM_MEMBERSMANAGER_THERE_HAS_BEEN_AN_ERROR="There has been an error." +COM_MEMBERSMANAGER_THERE_WAS_AN_ERROR_PLEASE_TRY_AGAIN_LATER_IF_THIS_ERROR_CONTINUES_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="There was an error, please try again later. If this error continues, contact your system administrator." COM_MEMBERSMANAGER_THE_PROFILE_WILL_BE_CROPPED_TO_THIS_SIZE="The profile will be cropped to this size" COM_MEMBERSMANAGER_TRASHED="Trashed" COM_MEMBERSMANAGER_TYPE="Type" @@ -494,6 +692,10 @@ COM_MEMBERSMANAGER_TYPES_CREATE_DESC="Allows the users in this group to create c COM_MEMBERSMANAGER_TYPES_DELETE="Types Delete" COM_MEMBERSMANAGER_TYPES_DELETE_DESC="Allows the users in this group to delete delete types" COM_MEMBERSMANAGER_TYPES_EDIT="Types Edit" +COM_MEMBERSMANAGER_TYPES_EDIT_ADD_RELATIONSHIP="Types Edit Add Relationship" +COM_MEMBERSMANAGER_TYPES_EDIT_ADD_RELATIONSHIP_DESC="Allows the users in this group to edit add relationship of type" +COM_MEMBERSMANAGER_TYPES_EDIT_COMMUNICATE="Types Edit Communicate" +COM_MEMBERSMANAGER_TYPES_EDIT_COMMUNICATE_DESC="Allows the users in this group to edit communicate of type" COM_MEMBERSMANAGER_TYPES_EDIT_CREATED_BY="Types Edit Created By" COM_MEMBERSMANAGER_TYPES_EDIT_CREATED_BY_DESC="Allows the users in this group to update the created by of the edit created by types" COM_MEMBERSMANAGER_TYPES_EDIT_CREATED_DATE="Types Edit Created Date" @@ -501,6 +703,10 @@ COM_MEMBERSMANAGER_TYPES_EDIT_CREATED_DATE_DESC="Allows the users in this group COM_MEMBERSMANAGER_TYPES_EDIT_DESC="Allows the users in this group to edit the type" COM_MEMBERSMANAGER_TYPES_EDIT_DESCRIPTION="Types Edit Description" COM_MEMBERSMANAGER_TYPES_EDIT_DESCRIPTION_DESC="Allows the users in this group to edit description of type" +COM_MEMBERSMANAGER_TYPES_EDIT_EDIT_RELATIONSHIP="Types Edit Edit Relationship" +COM_MEMBERSMANAGER_TYPES_EDIT_EDIT_RELATIONSHIP_DESC="Allows the users in this group to edit edit relationship of type" +COM_MEMBERSMANAGER_TYPES_EDIT_FIELD_TYPE="Types Edit Field Type" +COM_MEMBERSMANAGER_TYPES_EDIT_FIELD_TYPE_DESC="Allows the users in this group to edit field type of type" COM_MEMBERSMANAGER_TYPES_EDIT_GROUPS_ACCESS="Types Edit Groups Access" COM_MEMBERSMANAGER_TYPES_EDIT_GROUPS_ACCESS_DESC="Allows the users in this group to edit groups access of type" COM_MEMBERSMANAGER_TYPES_EDIT_GROUPS_TARGET="Types Edit Groups Target" @@ -511,8 +717,12 @@ COM_MEMBERSMANAGER_TYPES_EDIT_OWN="Types Edit Own" COM_MEMBERSMANAGER_TYPES_EDIT_OWN_DESC="Allows the users in this group to edit edit own types created by them" COM_MEMBERSMANAGER_TYPES_EDIT_STATE="Types Edit State" COM_MEMBERSMANAGER_TYPES_EDIT_STATE_DESC="Allows the users in this group to update the state of the type" +COM_MEMBERSMANAGER_TYPES_EDIT_TYPE="Types Edit Type" +COM_MEMBERSMANAGER_TYPES_EDIT_TYPE_DESC="Allows the users in this group to edit type of type" COM_MEMBERSMANAGER_TYPES_EDIT_VERSION="Types Edit Version" COM_MEMBERSMANAGER_TYPES_EDIT_VERSION_DESC="Allows users in this group to edit versions of version types" +COM_MEMBERSMANAGER_TYPES_EDIT_VIEW_RELATIONSHIP="Types Edit View Relationship" +COM_MEMBERSMANAGER_TYPES_EDIT_VIEW_RELATIONSHIP_DESC="Allows the users in this group to edit view relationship of type" COM_MEMBERSMANAGER_TYPES_EXPORT="Types Export" COM_MEMBERSMANAGER_TYPES_EXPORT_DESC="Allows the users in this group to export export types" COM_MEMBERSMANAGER_TYPES_IMPORT="Types Import" @@ -534,9 +744,20 @@ COM_MEMBERSMANAGER_TYPES_N_ITEMS_UNFEATURED="%s Types unfeatured." COM_MEMBERSMANAGER_TYPES_N_ITEMS_UNFEATURED_1="%s Type unfeatured." COM_MEMBERSMANAGER_TYPES_N_ITEMS_UNPUBLISHED="%s Types unpublished." COM_MEMBERSMANAGER_TYPES_N_ITEMS_UNPUBLISHED_1="%s Type unpublished." +COM_MEMBERSMANAGER_TYPES_SUBMENU="Types Submenu" +COM_MEMBERSMANAGER_TYPES_SUBMENU_DESC="Allows the users in this group to submenu of type" +COM_MEMBERSMANAGER_TYPE_ADD_RELATIONSHIP="Add Relationship" +COM_MEMBERSMANAGER_TYPE_ADD_RELATIONSHIP_DESCRIPTION="Allow relationships to be created across members." +COM_MEMBERSMANAGER_TYPE_ADD_RELATIONSHIP_LABEL="Allow Relationships" +COM_MEMBERSMANAGER_TYPE_ADVANCE="Advance" COM_MEMBERSMANAGER_TYPE_ALIAS="Alias" COM_MEMBERSMANAGER_TYPE_ALIAS_HINT="Auto-generated from name" COM_MEMBERSMANAGER_TYPE_ALIAS_LABEL="Alias" +COM_MEMBERSMANAGER_TYPE_ALL="All" +COM_MEMBERSMANAGER_TYPE_CHECKBOXES="Checkboxes" +COM_MEMBERSMANAGER_TYPE_COMMUNICATE="Communicate" +COM_MEMBERSMANAGER_TYPE_COMMUNICATE_DESCRIPTION="Set the type of behavior this member type has towards the communication component if available. None - do not show in communication, Only Selected - show only the selected by the member in profile, All - show all to all members." +COM_MEMBERSMANAGER_TYPE_COMMUNICATE_LABEL="Communication" COM_MEMBERSMANAGER_TYPE_CREATED_BY_DESC="The user that created this Type." COM_MEMBERSMANAGER_TYPE_CREATED_BY_LABEL="Created By" COM_MEMBERSMANAGER_TYPE_CREATED_DATE_DESC="The date this Type was created." @@ -547,7 +768,13 @@ COM_MEMBERSMANAGER_TYPE_DESCRIPTION_HINT="Add Description Here" COM_MEMBERSMANAGER_TYPE_DESCRIPTION_LABEL="Description" COM_MEMBERSMANAGER_TYPE_DETAILS="Details" COM_MEMBERSMANAGER_TYPE_EDIT="Editing the Type" +COM_MEMBERSMANAGER_TYPE_EDIT_RELATIONSHIP="Edit Relationship" +COM_MEMBERSMANAGER_TYPE_EDIT_RELATIONSHIP_DESCRIPTION="Select the type/s that can edit the relationships." +COM_MEMBERSMANAGER_TYPE_EDIT_RELATIONSHIP_LABEL="can Edit" COM_MEMBERSMANAGER_TYPE_ERROR_UNIQUE_ALIAS="Another Type has the same alias." +COM_MEMBERSMANAGER_TYPE_FIELD_TYPE="Field Type" +COM_MEMBERSMANAGER_TYPE_FIELD_TYPE_DESCRIPTION="Select the type of field to use when a member selects the relationship. Checkboxes are ideal when there are not many of these particular type of members, otherwise use the list type." +COM_MEMBERSMANAGER_TYPE_FIELD_TYPE_LABEL="Selection Field Type" COM_MEMBERSMANAGER_TYPE_GROUPS_ACCESS="Groups Access" COM_MEMBERSMANAGER_TYPE_GROUPS_ACCESS_DESCRIPTION="Select access group/s" COM_MEMBERSMANAGER_TYPE_GROUPS_ACCESS_LABEL="Access Group/s" @@ -555,6 +782,7 @@ COM_MEMBERSMANAGER_TYPE_GROUPS_TARGET="Groups Target" COM_MEMBERSMANAGER_TYPE_GROUPS_TARGET_DESCRIPTION="Select target group/s" COM_MEMBERSMANAGER_TYPE_GROUPS_TARGET_LABEL="Target Group/s" COM_MEMBERSMANAGER_TYPE_ID="Id" +COM_MEMBERSMANAGER_TYPE_LIST="List" COM_MEMBERSMANAGER_TYPE_MODIFIED_BY_DESC="The last user that modified this Type." COM_MEMBERSMANAGER_TYPE_MODIFIED_BY_LABEL="Modified By" COM_MEMBERSMANAGER_TYPE_MODIFIED_DATE_DESC="The date this Type was modified." @@ -565,13 +793,23 @@ COM_MEMBERSMANAGER_TYPE_NAME_HINT="Name Here" COM_MEMBERSMANAGER_TYPE_NAME_LABEL="Name" COM_MEMBERSMANAGER_TYPE_NAME_MESSAGE="Error! Please add name here." COM_MEMBERSMANAGER_TYPE_NEW="A New Type" +COM_MEMBERSMANAGER_TYPE_NO="No" +COM_MEMBERSMANAGER_TYPE_NONE="None" +COM_MEMBERSMANAGER_TYPE_ONLY_SELECTED="Only Selected" COM_MEMBERSMANAGER_TYPE_ORDERING_LABEL="Ordering" COM_MEMBERSMANAGER_TYPE_PERMISSION="Permissions" COM_MEMBERSMANAGER_TYPE_PUBLISHING="Publishing" COM_MEMBERSMANAGER_TYPE_SAVE_WARNING="Alias already existed so a number was added at the end. You can re-edit the Type to customise the alias." COM_MEMBERSMANAGER_TYPE_STATUS="Status" +COM_MEMBERSMANAGER_TYPE_TYPE="Type" +COM_MEMBERSMANAGER_TYPE_TYPE_DESCRIPTION="Select the type/s" +COM_MEMBERSMANAGER_TYPE_TYPE_LABEL="can Link" COM_MEMBERSMANAGER_TYPE_VERSION_DESC="A count of the number of times this Type has been revised." COM_MEMBERSMANAGER_TYPE_VERSION_LABEL="Revision" +COM_MEMBERSMANAGER_TYPE_VIEW_RELATIONSHIP="View Relationship" +COM_MEMBERSMANAGER_TYPE_VIEW_RELATIONSHIP_DESCRIPTION="Select the type/s that can view the relationships." +COM_MEMBERSMANAGER_TYPE_VIEW_RELATIONSHIP_LABEL="can View" +COM_MEMBERSMANAGER_TYPE_YES="Yes" COM_MEMBERSMANAGER_USE_BATCH="Use Batch" COM_MEMBERSMANAGER_USE_BATCH_DESC=" Allows users in this group to use batch copy/update method." COM_MEMBERSMANAGER_VALUE_ALREADY_TAKEN_PLEASE_TRY_AGAIN="Value already taken, please try again." @@ -579,8 +817,11 @@ COM_MEMBERSMANAGER_VERSION="Version" COM_MEMBERSMANAGER_WARNING_IMPORT_FILE_ERROR="Warning, import file error." COM_MEMBERSMANAGER_WARNING_IMPORT_UPLOAD_ERROR="Warning, import upload error." COM_MEMBERSMANAGER_WEBSITE="Website" +COM_MEMBERSMANAGER_YOU_CAN_NOT_DELETE_BSB_FIRST_MOVE_ALL_SUB_ACCOUNTS_TO_NEW_MAIN_MEMBER="You can not delete %s, first move all sub account/s to new main member." COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_ADD_DATA_TO_S_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="You do not have permission to add data to %s, please contact your system administrator." COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_S_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="You do not have permission to edit %s, please contact your system administrator." +COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_THIS_MEMBER_RELATIONSHIPS_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="You do not have permission to edit this member relationships, please contact your system administrator." +COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_THIS_MEMBER_TYPE_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="You do not have permission to edit this member type, please contact your system administrator." COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_REMOVE_THIS_FILE="You do not have permission to remove this file." COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_UPLOAD_AN="You do not have permission to upload an" COM_MEMBERSMANAGER__HAS_BEEN_CHECKED_OUT_BY_S="% has been checked out by %s" \ No newline at end of file diff --git a/admin/language/en-GB/en-GB.com_membersmanager.sys.ini b/admin/language/en-GB/en-GB.com_membersmanager.sys.ini index e54c84a..92775ea 100644 --- a/admin/language/en-GB/en-GB.com_membersmanager.sys.ini +++ b/admin/language/en-GB/en-GB.com_membersmanager.sys.ini @@ -22,6 +22,8 @@ COM_MEMBERSMANAGER_MEMBERS_ACCESS_PASSWORD_CHECK_DESC="Allows the users in this COM_MEMBERSMANAGER_MEMBERS_ACCESS_PASSWORD_DESC="Allows the users in this group to access password of member" COM_MEMBERSMANAGER_MEMBERS_ACCESS_PROFILE_IMAGE="Members Access Profile Image" COM_MEMBERSMANAGER_MEMBERS_ACCESS_PROFILE_IMAGE_DESC="Allows the users in this group to access profile image of member" +COM_MEMBERSMANAGER_MEMBERS_ACCESS_SITE="Members (Site) Access" +COM_MEMBERSMANAGER_MEMBERS_ACCESS_SITE_DESC=" Allows the users in this group to access site members." COM_MEMBERSMANAGER_MEMBERS_ACCESS_USEREMAIL="Members Access Useremail" COM_MEMBERSMANAGER_MEMBERS_ACCESS_USEREMAIL_DESC="Allows the users in this group to access useremail of member" COM_MEMBERSMANAGER_MEMBERS_ACCESS_USERNAME="Members Access Username" @@ -74,6 +76,8 @@ COM_MEMBERSMANAGER_MEMBERS_EXPORT="Members Export" COM_MEMBERSMANAGER_MEMBERS_EXPORT_DESC="Allows the users in this group to export export members" COM_MEMBERSMANAGER_MEMBERS_IMPORT="Members Import" COM_MEMBERSMANAGER_MEMBERS_IMPORT_DESC="Allows the users in this group to import import members" +COM_MEMBERSMANAGER_MEMBERS_SUBMENU="Members Submenu" +COM_MEMBERSMANAGER_MEMBERS_SUBMENU_DESC="Allows the users in this group to submenu of member" COM_MEMBERSMANAGER_MEMBERS_VIEW_ACCOUNT="Members View Account" COM_MEMBERSMANAGER_MEMBERS_VIEW_ACCOUNT_DESC="Allows the users in this group to view account of member" COM_MEMBERSMANAGER_MEMBERS_VIEW_EMAIL="Members View Email" @@ -106,6 +110,9 @@ COM_MEMBERSMANAGER_MENU="★ Members Manager" COM_MEMBERSMANAGER_MENU_CPANEL_DESC="Control Panel for Members" COM_MEMBERSMANAGER_MENU_CPANEL_OPTION="cPanel" COM_MEMBERSMANAGER_MENU_CPANEL_TITLE="cPanel" +COM_MEMBERSMANAGER_MENU_MEMBERS_DESC="Any List of Member Details" +COM_MEMBERSMANAGER_MENU_MEMBERS_OPTION="Members" +COM_MEMBERSMANAGER_MENU_MEMBERS_TITLE="Members" COM_MEMBERSMANAGER_TYPES_ACCESS="Types Access" COM_MEMBERSMANAGER_TYPES_ACCESS_DESC="Allows the users in this group to access access types" COM_MEMBERSMANAGER_TYPES_BATCH_USE="Types Batch Use" @@ -115,6 +122,10 @@ COM_MEMBERSMANAGER_TYPES_CREATE_DESC="Allows the users in this group to create c COM_MEMBERSMANAGER_TYPES_DELETE="Types Delete" COM_MEMBERSMANAGER_TYPES_DELETE_DESC="Allows the users in this group to delete delete types" COM_MEMBERSMANAGER_TYPES_EDIT="Types Edit" +COM_MEMBERSMANAGER_TYPES_EDIT_ADD_RELATIONSHIP="Types Edit Add Relationship" +COM_MEMBERSMANAGER_TYPES_EDIT_ADD_RELATIONSHIP_DESC="Allows the users in this group to edit add relationship of type" +COM_MEMBERSMANAGER_TYPES_EDIT_COMMUNICATE="Types Edit Communicate" +COM_MEMBERSMANAGER_TYPES_EDIT_COMMUNICATE_DESC="Allows the users in this group to edit communicate of type" COM_MEMBERSMANAGER_TYPES_EDIT_CREATED_BY="Types Edit Created By" COM_MEMBERSMANAGER_TYPES_EDIT_CREATED_BY_DESC="Allows the users in this group to update the created by of the edit created by types" COM_MEMBERSMANAGER_TYPES_EDIT_CREATED_DATE="Types Edit Created Date" @@ -122,6 +133,10 @@ COM_MEMBERSMANAGER_TYPES_EDIT_CREATED_DATE_DESC="Allows the users in this group COM_MEMBERSMANAGER_TYPES_EDIT_DESC="Allows the users in this group to edit the type" COM_MEMBERSMANAGER_TYPES_EDIT_DESCRIPTION="Types Edit Description" COM_MEMBERSMANAGER_TYPES_EDIT_DESCRIPTION_DESC="Allows the users in this group to edit description of type" +COM_MEMBERSMANAGER_TYPES_EDIT_EDIT_RELATIONSHIP="Types Edit Edit Relationship" +COM_MEMBERSMANAGER_TYPES_EDIT_EDIT_RELATIONSHIP_DESC="Allows the users in this group to edit edit relationship of type" +COM_MEMBERSMANAGER_TYPES_EDIT_FIELD_TYPE="Types Edit Field Type" +COM_MEMBERSMANAGER_TYPES_EDIT_FIELD_TYPE_DESC="Allows the users in this group to edit field type of type" COM_MEMBERSMANAGER_TYPES_EDIT_GROUPS_ACCESS="Types Edit Groups Access" COM_MEMBERSMANAGER_TYPES_EDIT_GROUPS_ACCESS_DESC="Allows the users in this group to edit groups access of type" COM_MEMBERSMANAGER_TYPES_EDIT_GROUPS_TARGET="Types Edit Groups Target" @@ -132,11 +147,17 @@ COM_MEMBERSMANAGER_TYPES_EDIT_OWN="Types Edit Own" COM_MEMBERSMANAGER_TYPES_EDIT_OWN_DESC="Allows the users in this group to edit edit own types created by them" COM_MEMBERSMANAGER_TYPES_EDIT_STATE="Types Edit State" COM_MEMBERSMANAGER_TYPES_EDIT_STATE_DESC="Allows the users in this group to update the state of the type" +COM_MEMBERSMANAGER_TYPES_EDIT_TYPE="Types Edit Type" +COM_MEMBERSMANAGER_TYPES_EDIT_TYPE_DESC="Allows the users in this group to edit type of type" COM_MEMBERSMANAGER_TYPES_EDIT_VERSION="Types Edit Version" COM_MEMBERSMANAGER_TYPES_EDIT_VERSION_DESC="Allows users in this group to edit versions of version types" +COM_MEMBERSMANAGER_TYPES_EDIT_VIEW_RELATIONSHIP="Types Edit View Relationship" +COM_MEMBERSMANAGER_TYPES_EDIT_VIEW_RELATIONSHIP_DESC="Allows the users in this group to edit view relationship of type" COM_MEMBERSMANAGER_TYPES_EXPORT="Types Export" COM_MEMBERSMANAGER_TYPES_EXPORT_DESC="Allows the users in this group to export export types" COM_MEMBERSMANAGER_TYPES_IMPORT="Types Import" COM_MEMBERSMANAGER_TYPES_IMPORT_DESC="Allows the users in this group to import import types" +COM_MEMBERSMANAGER_TYPES_SUBMENU="Types Submenu" +COM_MEMBERSMANAGER_TYPES_SUBMENU_DESC="Allows the users in this group to submenu of type" COM_MEMBERSMANAGER_USE_BATCH="Use Batch" COM_MEMBERSMANAGER_USE_BATCH_DESC=" Allows users in this group to use batch copy/update method." \ No newline at end of file diff --git a/admin/layouts/batchselection.php b/admin/layouts/batchselection.php index 5a29d28..50c7882 100644 --- a/admin/layouts/batchselection.php +++ b/admin/layouts/batchselection.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/member/membership_above.php b/admin/layouts/member/membership_above.php index 2c4cf6f..465b5d4 100644 --- a/admin/layouts/member/membership_above.php +++ b/admin/layouts/member/membership_above.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/member/membership_left.php b/admin/layouts/member/membership_left.php index 343768d..6da2add 100644 --- a/admin/layouts/member/membership_left.php +++ b/admin/layouts/member/membership_left.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/member/membership_right.php b/admin/layouts/member/membership_right.php index d3e9d37..06ff934 100644 --- a/admin/layouts/member/membership_right.php +++ b/admin/layouts/member/membership_right.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/member/publishing.php b/admin/layouts/member/publishing.php index aeaea28..2778547 100644 --- a/admin/layouts/member/publishing.php +++ b/admin/layouts/member/publishing.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/member/publlshing.php b/admin/layouts/member/publlshing.php index 666edf5..7a32c45 100644 --- a/admin/layouts/member/publlshing.php +++ b/admin/layouts/member/publlshing.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/type/advance_left.php b/admin/layouts/type/advance_left.php new file mode 100644 index 0000000..39f7aae --- /dev/null +++ b/admin/layouts/type/advance_left.php @@ -0,0 +1,42 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +$form = $displayData->getForm(); + +$fields = $displayData->get('fields') ?: array( + 'add_relationship', + 'type', + 'edit_relationship', + 'view_relationship' +); + +$hiddenFields = $displayData->get('hidden_fields') ?: array(); + +foreach ($fields as $field) +{ + $field = is_array($field) ? $field : array($field); + foreach ($field as $f) + { + if ($form->getField($f)) + { + if (in_array($f, $hiddenFields)) + { + $form->setFieldAttribute($f, 'type', 'hidden'); + } + + echo $form->renderField($f); + break; + } + } +} diff --git a/admin/layouts/type/advance_right.php b/admin/layouts/type/advance_right.php new file mode 100644 index 0000000..eaafb64 --- /dev/null +++ b/admin/layouts/type/advance_right.php @@ -0,0 +1,40 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +$form = $displayData->getForm(); + +$fields = $displayData->get('fields') ?: array( + 'communicate', + 'field_type' +); + +$hiddenFields = $displayData->get('hidden_fields') ?: array(); + +foreach ($fields as $field) +{ + $field = is_array($field) ? $field : array($field); + foreach ($field as $f) + { + if ($form->getField($f)) + { + if (in_array($f, $hiddenFields)) + { + $form->setFieldAttribute($f, 'type', 'hidden'); + } + + echo $form->renderField($f); + break; + } + } +} diff --git a/admin/layouts/type/details_above.php b/admin/layouts/type/details_above.php index 5c862d9..ae61281 100644 --- a/admin/layouts/type/details_above.php +++ b/admin/layouts/type/details_above.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/type/details_fullwidth.php b/admin/layouts/type/details_fullwidth.php index d10fcdf..8353fc2 100644 --- a/admin/layouts/type/details_fullwidth.php +++ b/admin/layouts/type/details_fullwidth.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/type/details_left.php b/admin/layouts/type/details_left.php index e574e0a..ddd5bda 100644 --- a/admin/layouts/type/details_left.php +++ b/admin/layouts/type/details_left.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/type/details_right.php b/admin/layouts/type/details_right.php index e19aaaf..f117838 100644 --- a/admin/layouts/type/details_right.php +++ b/admin/layouts/type/details_right.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/type/publishing.php b/admin/layouts/type/publishing.php index 8555159..b295f02 100644 --- a/admin/layouts/type/publishing.php +++ b/admin/layouts/type/publishing.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/layouts/type/publlshing.php b/admin/layouts/type/publlshing.php index 666edf5..7a32c45 100644 --- a/admin/layouts/type/publlshing.php +++ b/admin/layouts/type/publlshing.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/membersmanager.php b/admin/membersmanager.php index 2473e4e..a5139bc 100644 --- a/admin/membersmanager.php +++ b/admin/membersmanager.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/models/ajax.php b/admin/models/ajax.php index bd9af21..4e7ec1e 100644 --- a/admin/models/ajax.php +++ b/admin/models/ajax.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -58,6 +58,48 @@ class MembersmanagerModelAjax extends JModelList } return false; } + + // get placeholder header if available + public function getPlaceHolderHeaders($component) + { + if ('com_membersmanager' === $component) + { + return JText::_('COM_MEMBERSMANAGER'); + } + return MembersmanagerHelper::getComponentName($component); + } + + // get chart image link + public function getChartImageLink($image) + { + $view = $this->getViewID(); + // make sure we are in the (allowed) view + if (isset($view['a_view']) && ($view['a_view'] === 'message' || $view['a_view'] === 'profile')) + { + // build image name + $imageName = md5($image . 'jnst_f0r_dumm!es'); + // build image data + $image = explode('base64,', $image); unset($image[0]); $image = str_replace(' ', '+', implode('', $image)); + // validate Base64 + if (($image = MembersmanagerHelper::openValidBase64($image, null, false)) !== false) + { + // validate just png (for now) + $png_binary_check = "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"; + if (substr($image, 0, strlen($png_binary_check)) === $png_binary_check) + { + // build image path + $imagepath = MembersmanagerHelper::getFolderPath('path', 'chartpath') . $imageName . '.png'; + // now write the file if not exists + if (file_exists($imagepath) || MembersmanagerHelper::writeFile($imagepath, $image)) + { + // build and return image link + return array('link' => MembersmanagerHelper::getFolderPath('url', 'chartpath') . $imageName . '.png'); + } + } + } + } + return false; + } // set some buckets protected $target; @@ -605,13 +647,77 @@ class MembersmanagerModelAjax extends JModelList } + /** + * get any placeholder + * + * @param string $getType Name get type + * + * @return string The html string of placeholders + * + */ + public function getAnyPlaceHolders($getType) + { + // check if we should add a header + if (method_exists(__CLASS__, 'getPlaceHolderHeaders') && ($string = $this->getPlaceHolderHeaders($getType)) !== false) + { + $string = JText::_($string) . ' '; + $header = '

    ' . $string . '

    '; + } + else + { + $string = ''; + $header = ''; + } + // get placeholders + if ($placeholders = MembersmanagerHelper::getAnyPlaceHolders($getType)) + { + return '
    ' . $header . '' . + implode(' ', $placeholders) . + '
    '; + } + // not found + return '

    ' . + $string . JText::_('COM_MEMBERSMANAGER_PLACEHOLDERS_NOT_FOUND') . + '!

    ' . + JText::_('COM_MEMBERSMANAGER_THERE_WAS_AN_ERROR_PLEASE_TRY_AGAIN_LATER_IF_THIS_ERROR_CONTINUES_CONTACT_YOUR_SYSTEM_ADMINISTRATOR') . + '
    '; + } + + + /** + * get the placeholder + * + * @param string $getType Name get type + * + * @return string The html string of placeholders + * + */ public function getPlaceHolders($getType) { + // check if we should add a header + if (method_exists(__CLASS__, 'getPlaceHolderHeaders') && ($string = $this->getPlaceHolderHeaders($getType)) !== false) + { + $string = JText::_($string) . ' '; + $header = '

    ' . $string . '

    '; + } + else + { + $string = ''; + $header = ''; + } + // get placeholders if ($placeholders = MembersmanagerHelper::getPlaceHolders($getType)) { - return ''. implode(' ', $placeholders).''; + return '
    ' . $header . '' . + implode(' ', $placeholders) . + '
    '; } - return JText::_('COM_MEMBERSMANAGER_NO_PLACEHOLDERS_WERE_FOUND_PLEASE_TRY_AGAIN_LATER'); + // not found + return '

    ' . + $string . JText::_('COM_MEMBERSMANAGER_PLACEHOLDERS_NOT_FOUND') . + '!

    ' . + JText::_('COM_MEMBERSMANAGER_THERE_WAS_AN_ERROR_PLEASE_TRY_AGAIN_LATER_IF_THIS_ERROR_CONTINUES_CONTACT_YOUR_SYSTEM_ADMINISTRATOR') . + '
    '; } } diff --git a/admin/models/fields/mainmembers.php b/admin/models/fields/mainmembers.php index 0579837..9394a2a 100644 --- a/admin/models/fields/mainmembers.php +++ b/admin/models/fields/mainmembers.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -142,8 +142,36 @@ class JFormFieldMainmembers extends JFormFieldList */ protected function getOptions() { - // load the db opbject + + // get the user + $my = JFactory::getUser(); + // load the db opbject $db = JFactory::getDBO(); + // start the query + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id','a.user','a.account','a.name','a.email','a.token'),array('id','main_member_user','account','name','email','token'))); + $query->from($db->quoteName('#__membersmanager_member', 'a')); + $query->where($db->quoteName('a.published') . ' >= 1'); + $query->where($db->quoteName('a.account') . ' = 1 OR ' . $db->quoteName('a.account') . ' = 2'); + // check if current user is an admin + if (!$my->authorise('core.options', 'com_membersmanager')) + { + // get user access groups + if (($user_access_types = MembersmanagerHelper::getAccess($my)) === false || !MembersmanagerHelper::checkArray($user_access_types)) + { + return false; + } + //filter by type + $query->join('LEFT', $db->quoteName('#__membersmanager_type_map', 't') . ' ON (' . $db->quoteName('a.id') . ' = ' . $db->quoteName('t.member') . ')'); + $user_access_types = implode(',', $user_access_types); + $query->where('t.type IN (' . $user_access_types . ')'); + // also filter by access (will keep an eye on this) + $groups = implode(',', $my->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $groups . ')'); + } + $query->order('a.user ASC'); + $db->setQuery((string)$query); + $items = $db->loadObjectList(); // get the input from url $jinput = JFactory::getApplication()->input; // get the id @@ -152,50 +180,8 @@ class JFormFieldMainmembers extends JFormFieldList { $main_member = MembersmanagerHelper::getVar('member', $id, 'id', 'main_member'); } - // get the user - $my = JFactory::getUser(); - // start the query - $query = $db->getQuery(true); - $query->select($db->quoteName(array('a.id','a.user','a.account','a.name','a.email','a.token'),array('id','main_member_user','account','name','email','token'))); - $query->from($db->quoteName('#__membersmanager_member', 'a')); - $query->where($db->quoteName('a.published') . ' >= 1'); - $query->where($db->quoteName('a.account') . ' = 1 OR ' . $db->quoteName('a.account') . ' = 2'); - // check if current user is a supper admin - if (!$my->authorise('core.admin')) - { - // get user access groups - $user_access_types = MembersmanagerHelper::getAccess($my); - // user must have access - if (isset($user_access_types) && MembersmanagerHelper::checkArray($user_access_types)) - { - // only get members of the type this user has access to - $query->where('a.type IN (' . implode(',', $user_access_types) . ')'); - // get current member type - if (($type= MembersmanagerHelper::getVar('member', $id, 'id', 'type')) !== false) - { - // check if this member is in the user access types - if (in_array($type, $user_access_types)) - { - // no need to load this member - $main_member = 0; - } - } - } - elseif (isset($main_member) && $main_member > 0) - { - // load this main member only - $query->where($db->quoteName('a.id') . ' = ' . (int) $main_member); - } - else - { - return false; - } - } - $query->order('a.user ASC'); - $db->setQuery((string)$query); - $items = $db->loadObjectList(); $options = array(); - if ($items) + if (MembersmanagerHelper::checkArray($items)) { // only add if more then one value found if (count( (array) $items) > 1) diff --git a/admin/models/fields/memberuser.php b/admin/models/fields/memberuser.php index 3888bbc..69974c4 100644 --- a/admin/models/fields/memberuser.php +++ b/admin/models/fields/memberuser.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/models/fields/onetomanycomponents.php b/admin/models/fields/onetomanycomponents.php new file mode 100644 index 0000000..538d871 --- /dev/null +++ b/admin/models/fields/onetomanycomponents.php @@ -0,0 +1,95 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +// import the list field type +jimport('joomla.form.helper'); +JFormHelper::loadFieldClass('list'); + +/** + * Onetomanycomponents Form Field class for the Membersmanager component + */ +class JFormFieldOnetomanycomponents extends JFormFieldList +{ + /** + * The onetomanycomponents field type. + * + * @var string + */ + public $type = 'onetomanycomponents'; + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + */ + protected function getOptions() + { + + $options = array(); + // get the component name + $component = 'membersmanager'; + // set the element name + $_component = 'com_membersmanager'; + // check if it is already set + if (!class_exists('MembersmanagerHelper')) + { + // set the correct path focus + $focus = JPATH_ADMINISTRATOR; + // check if we are in the site area + if (JFactory::getApplication()->isSite()) + { + // set admin path + $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; + // change the focus + $focus = JPATH_ROOT; + } + // set path based on focus + $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; + // check if file exist, if not try admin again. + if (file_exists($path)) + { + // make sure to load the helper + JLoader::register('MembersmanagerHelper', $path); + } + // fallback option + elseif (isset($adminPath) && file_exists($adminPath)) + { + // make sure to load the helper + JLoader::register('MembersmanagerHelper', $adminPath); + } + else + { + // could not find this + return false; + } + } + // Get the components + if (($components = MembersmanagerHelper::getAllComponents(2)) !== false) + { + // since used in multiple fields we need to test if this is a multi select or not + $multiple = $this->getAttribute('multiple', false); + if (!$multiple || $multiple === 'false') + { + $options[] = JHtml::_('select.option', '', JText::_('COM_MEMBERSMANAGER_SELECT_AN_OPTION')); + } + // now load the items + foreach($components as $item) + { + $type = (isset($item->params->activate_membersmanager_assessment)) ? $item->params->assessment_type_name : JText::_('COM_MEMBERSMANAGER_INFO'); + $options[] = JHtml::_('select.option', $item->element, $item->name . ' (' . $type . ')'); + } + } + return $options; + } +} diff --git a/admin/models/fields/onetoonecomponents.php b/admin/models/fields/onetoonecomponents.php new file mode 100644 index 0000000..8753232 --- /dev/null +++ b/admin/models/fields/onetoonecomponents.php @@ -0,0 +1,95 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +// import the list field type +jimport('joomla.form.helper'); +JFormHelper::loadFieldClass('list'); + +/** + * Onetoonecomponents Form Field class for the Membersmanager component + */ +class JFormFieldOnetoonecomponents extends JFormFieldList +{ + /** + * The onetoonecomponents field type. + * + * @var string + */ + public $type = 'onetoonecomponents'; + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + */ + protected function getOptions() + { + + $options = array(); + // get the component name + $component = 'membersmanager'; + // set the element name + $_component = 'com_membersmanager'; + // check if it is already set + if (!class_exists('MembersmanagerHelper')) + { + // set the correct path focus + $focus = JPATH_ADMINISTRATOR; + // check if we are in the site area + if (JFactory::getApplication()->isSite()) + { + // set admin path + $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; + // change the focus + $focus = JPATH_ROOT; + } + // set path based on focus + $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; + // check if file exist, if not try admin again. + if (file_exists($path)) + { + // make sure to load the helper + JLoader::register('MembersmanagerHelper', $path); + } + // fallback option + elseif (isset($adminPath) && file_exists($adminPath)) + { + // make sure to load the helper + JLoader::register('MembersmanagerHelper', $adminPath); + } + else + { + // could not find this + return false; + } + } + // Get the components + if (($components = MembersmanagerHelper::getAllComponents(1)) !== false) + { + // since used in multiple fields we need to test if this is a multi select or not + $multiple = $this->getAttribute('multiple', false); + if (!$multiple || $multiple === 'false') + { + $options[] = JHtml::_('select.option', '', JText::_('COM_MEMBERSMANAGER_SELECT_AN_OPTION')); + } + // now load the items + foreach($components as $item) + { + $type = (isset($item->params->activate_membersmanager_assessment)) ? $item->params->assessment_type_name : JText::_('COM_MEMBERSMANAGER_INFO'); + $options[] = JHtml::_('select.option', $item->element, $item->name . ' (' . $type . ')'); + } + } + return $options; + } +} diff --git a/admin/models/fields/targettypes.php b/admin/models/fields/targettypes.php new file mode 100644 index 0000000..cad6ee9 --- /dev/null +++ b/admin/models/fields/targettypes.php @@ -0,0 +1,58 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +// import the list field type +jimport('joomla.form.helper'); +JFormHelper::loadFieldClass('list'); + +/** + * Targettypes Form Field class for the Membersmanager component + */ +class JFormFieldTargettypes extends JFormFieldList +{ + /** + * The targettypes field type. + * + * @var string + */ + public $type = 'targettypes'; + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + */ + protected function getOptions() + { + // load the db opbject + $db = JFactory::getDBO(); + // start query + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id','a.name'),array('id','target_type_name'))); + $query->from($db->quoteName('#__membersmanager_type', 'a')); + $query->where($db->quoteName('a.published') . ' >= 1'); + $query->order('a.name ASC'); + $db->setQuery((string)$query); + $items = $db->loadObjectList(); + $options = array(); + if ($items) + { + foreach($items as $item) + { + $options[] = JHtml::_('select.option', $item->id, $item->target_type_name); + } + } + return $options; + } +} diff --git a/admin/models/fields/types.php b/admin/models/fields/types.php index 4a62492..2b77743 100644 --- a/admin/models/fields/types.php +++ b/admin/models/fields/types.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -142,43 +142,14 @@ class JFormFieldTypes extends JFormFieldList */ protected function getOptions() { - // load the db opbject - $db = JFactory::getDBO(); - // get the user + // Get the user object. $user = JFactory::getUser(); - // access types - $accessTypes = MembersmanagerHelper::getAccess($user); - // start query + // Get the databse object. + $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select($db->quoteName(array('a.id','a.name'),array('id','type_name'))); $query->from($db->quoteName('#__membersmanager_type', 'a')); $query->where($db->quoteName('a.published') . ' >= 1'); - // check if current user is a supper admin - if (!$user->authorise('core.admin')) - { - // get the input from url - $jinput = JFactory::getApplication()->input; - // get the id - $id = $jinput->getInt('id', 0); - if ($id > 0) - { - $type = MembersmanagerHelper::getVar('type', $id, 'id', 'type'); - // check if part of user access - if (!MembersmanagerHelper::checkArray($accessTypes) || !in_array($type, $accessTypes)) - { - $accessTypes[] = $type; - } - } - // filter by access type - if (MembersmanagerHelper::checkArray($accessTypes)) - { - $query->where($db->quoteName('a.id') . ' in (' . implode(',', $accessTypes) . ')'); - } - else - { - return false; - } - } $query->order('a.name ASC'); $db->setQuery((string)$query); $items = $db->loadObjectList(); diff --git a/admin/models/fields/typesonmember.php b/admin/models/fields/typesonmember.php new file mode 100644 index 0000000..b8855d3 --- /dev/null +++ b/admin/models/fields/typesonmember.php @@ -0,0 +1,212 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +// import the list field type +jimport('joomla.form.helper'); +JFormHelper::loadFieldClass('list'); + +/** + * Typesonmember Form Field class for the Membersmanager component + */ +class JFormFieldTypesonmember extends JFormFieldList +{ + /** + * The typesonmember field type. + * + * @var string + */ + public $type = 'typesonmember'; + + /** + * Override to add new button + * + * @return string The field input markup. + * + * @since 3.2 + */ + protected function getInput() + { + // see if we should add buttons + $setButton = $this->getAttribute('button'); + // get html + $html = parent::getInput(); + // if true set button + if ($setButton === 'true') + { + $button = array(); + $script = array(); + $buttonName = $this->getAttribute('name'); + // get the input from url + $app = JFactory::getApplication(); + $jinput = $app->input; + // get the view name & id + $values = $jinput->getArray(array( + 'id' => 'int', + 'view' => 'word' + )); + // check if new item + $ref = ''; + $refJ = ''; + if (!is_null($values['id']) && strlen($values['view'])) + { + // only load referral if not new item. + $ref = '&ref=' . $values['view'] . '&refid=' . $values['id']; + $refJ = '&ref=' . $values['view'] . '&refid=' . $values['id']; + // get the return value. + $_uri = (string) JUri::getInstance(); + $_return = urlencode(base64_encode($_uri)); + // load return value. + $ref .= '&return=' . $_return; + $refJ .= '&return=' . $_return; + } + $user = JFactory::getUser(); + // only add if user allowed to create type + if ($user->authorise('type.create', 'com_membersmanager') && $app->isAdmin()) // TODO for now only in admin area. + { + // build Create button + $buttonNamee = trim($buttonName); + $buttonNamee = preg_replace('/_+/', ' ', $buttonNamee); + $buttonNamee = preg_replace('/\s+/', ' ', $buttonNamee); + $buttonNamee = preg_replace("/[^A-Za-z ]/", '', $buttonNamee); + $buttonNamee = ucfirst(strtolower($buttonNamee)); + $button[] = ' + '; + } + // only add if user allowed to edit type + if (($buttonName === 'type' || $buttonName === 'types') && $user->authorise('type.edit', 'com_membersmanager') && $app->isAdmin()) // TODO for now only in admin area. + { + // build edit button + $buttonNamee = trim($buttonName); + $buttonNamee = preg_replace('/_+/', ' ', $buttonNamee); + $buttonNamee = preg_replace('/\s+/', ' ', $buttonNamee); + $buttonNamee = preg_replace("/[^A-Za-z ]/", '', $buttonNamee); + $buttonNamee = ucfirst(strtolower($buttonNamee)); + $button[] = ''; + // build script + $script[] = " + jQuery(document).ready(function() { + jQuery('#adminForm').on('change', '#jform_".$buttonName."',function (e) { + e.preventDefault(); + var ".$buttonName."Value = jQuery('#jform_".$buttonName."').val(); + ".$buttonName."Button(".$buttonName."Value); + }); + var ".$buttonName."Value = jQuery('#jform_".$buttonName."').val(); + ".$buttonName."Button(".$buttonName."Value); + }); + function ".$buttonName."Button(value) { + if (value > 0) { + // hide the create button + jQuery('#".$buttonName."Create').hide(); + // show edit button + jQuery('#".$buttonName."Edit').show(); + var url = 'index.php?option=com_membersmanager&view=types&task=type.edit&id='+value+'".$refJ."'; + jQuery('#".$buttonName."Edit').attr('href', url); + } else { + // show the create button + jQuery('#".$buttonName."Create').show(); + // hide edit button + jQuery('#".$buttonName."Edit').hide(); + } + }"; + } + // check if button was created for type field. + if (is_array($button) && count($button) > 0) + { + // Load the needed script. + $document = JFactory::getDocument(); + $document->addScriptDeclaration(implode(' ',$script)); + // return the button attached to input field. + return '
    ' .$html . implode('',$button).'
    '; + } + } + return $html; + } + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + */ + protected function getOptions() + { + // load the db opbject + $db = JFactory::getDBO(); + // get the user + $user = JFactory::getUser(); + // start query + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id','a.name'),array('id','type_name'))); + $query->from($db->quoteName('#__membersmanager_type', 'a')); + $query->where($db->quoteName('a.published') . ' >= 1'); + // check if current user is an admin + if (!$user->authorise('core.options', 'com_membersmanager')) + { + // access types + $accessTypes = MembersmanagerHelper::getAccess($user); + // get the input from url + $jinput = JFactory::getApplication()->input; + // get the id + $id = $jinput->getInt('id', 0); + if ($id > 0) + { + $types = MembersmanagerHelper::getVar('member', $id, 'id', 'type'); + // convert type json to array + if (MembersmanagerHelper::checkJson($types)) + { + $types = json_decode($types, true); + } + // convert type int to array + if (is_numeric($types) && $types > 0) + { + $types = array($types); + } + // make sure we have an array + if (MembersmanagerHelper::checkArray($types)) + { + foreach ($types as $type) + { + // check if part of user access + if (!MembersmanagerHelper::checkArray($accessTypes) || !in_array($type, $accessTypes)) + { + $accessTypes[] = $type; + } + } + } + } + // filter by access type + if (MembersmanagerHelper::checkArray($accessTypes)) + { + $query->where($db->quoteName('a.id') . ' in (' . implode(',', $accessTypes) . ')'); + } + else + { + return false; + } + } + $query->order('a.name ASC'); + $db->setQuery((string)$query); + $items = $db->loadObjectList(); + $options = array(); + if ($items) + { + foreach($items as $item) + { + $options[] = JHtml::_('select.option', $item->id, $item->type_name); + } + } + return $options; + } +} diff --git a/admin/models/forms/member.js b/admin/models/forms/member.js index 2caf5fb..0fa6d39 100644 --- a/admin/models/forms/member.js +++ b/admin/models/forms/member.js @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -278,16 +278,16 @@ function getUserDetails(user){ }); } function getUserDetails_server(user){ - var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.getUserDetails&format=json&vdm="+vastDevMod); + var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.getUserDetails&format=json&raw=true&vdm="+vastDevMod); if(token.length > 0 && user > 0){ var request = 'token='+token+'&user='+user; } return jQuery.ajax({ type: 'GET', url: getUrl, - dataType: 'jsonp', + dataType: 'json', data: request, - jsonp: 'callback' + jsonp: false }); } function setUserDetails(result){ @@ -399,16 +399,16 @@ function removeFile(clearServer, target, flush, type){ } function removeFile_server(currentFileName, target, flush, type){ - var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.removeFile&format=json&vdm="+vastDevMod); + var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.removeFile&format=json&raw=true&vdm="+vastDevMod); if(token.length > 0 && target.length > 0 && type.length > 0){ var request = 'token='+token+'&filename='+currentFileName+'&target='+target+'&flush='+flush+'&type='+type; } return jQuery.ajax({ type: 'GET', url: getUrl, - dataType: 'jsonp', + dataType: 'json', data: request, - jsonp: 'callback' + jsonp: false }); } function isJsonString(str) { @@ -437,16 +437,16 @@ function isEmpty(obj) { function checkUnique_server(value, field){ - var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.checkUnique&format=json&vdm="+vastDevMod); + var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.checkUnique&format=json&raw=true&vdm="+vastDevMod); if(token.length > 0 && value.length > 0 && field.length > 0){ var request = 'token='+token+'&value='+value+'&field='+field; } return jQuery.ajax({ type: 'GET', url: getUrl, - dataType: 'jsonp', + dataType: 'json', data: request, - jsonp: 'callback' + jsonp: false }); } function checkUnique(value, field, show){ @@ -474,66 +474,4 @@ function checkUnique(value, field, show){ } }); } -} - -// set regions that are on the page -regions = {}; -var region = 0; -jQuery(document).ready(function($) -{ - jQuery("#jform_region option").each(function() - { - var key = jQuery(this).val(); - var text = jQuery(this).text(); - regions[key] = text; - }); - region = jQuery('#jform_region').val(); - getRegion(); -}); - -function getRegion_server(country){ - var getUrl = "index.php?option=com_membersmanager&task=ajax.getRegion&format=json"; - if(token.length > 0 && country > 0){ - var request = 'token='+token+'&country='+country; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'jsonp', - data: request, - jsonp: 'callback' - }); -} -function getRegion(){ - jQuery("#loading").show(); - // clear the selection - jQuery('#jform_region').find('option').remove().end(); - jQuery('#jform_region').trigger('liszt:updated'); - // get country value if set - var country = jQuery('#jform_country').val(); - getRegion_server(country).done(function(result) { - setRegion(result); - jQuery("#loading").hide(); - if (typeof regionButton !== 'undefined') { - // ensure button is correct - var region = jQuery('#jform_region').val(); - regionButton(region); - } - }); -} -function setRegion(array){ - if (array) { - jQuery('#jform_region').append(''); - jQuery.each( array, function( i, id ) { - if (id in regions) { - jQuery('#jform_region').append(''); - } - if (id == region) { - jQuery('#jform_region').val(id); - } - }); - } else { - jQuery('#jform_region').append(''); - } - jQuery('#jform_region').trigger('liszt:updated'); } diff --git a/admin/models/forms/member.xml b/admin/models/forms/member.xml index ad80e13..69997f6 100644 --- a/admin/models/forms/member.xml +++ b/admin/models/forms/member.xml @@ -263,14 +263,14 @@ message="COM_MEMBERSMANAGER_MEMBER_SURNAME_MESSAGE" hint="COM_MEMBERSMANAGER_MEMBER_SURNAME_HINT" /> - + diff --git a/admin/models/forms/type.js b/admin/models/forms/type.js index f783fe7..3aab7d3 100644 --- a/admin/models/forms/type.js +++ b/admin/models/forms/type.js @@ -1,11 +1,152 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html */ - +// Some Global Values +jform_vvvvvvyvvz_required = false; +jform_vvvvvvyvwa_required = false; +jform_vvvvvvyvwb_required = false; +jform_vvvvvvyvwc_required = false; + +// Initial Script +jQuery(document).ready(function() +{ + var add_relationship_vvvvvvy = jQuery("#jform_add_relationship input[type='radio']:checked").val(); + vvvvvvy(add_relationship_vvvvvvy); +}); + +// the vvvvvvy function +function vvvvvvy(add_relationship_vvvvvvy) +{ + // set the function logic + if (add_relationship_vvvvvvy == 1) + { + jQuery('#jform_communicate').closest('.control-group').show(); + jQuery('#jform_field_type').closest('.control-group').show(); + // add required attribute to field_type field + if (jform_vvvvvvyvvz_required) + { + updateFieldRequired('field_type',0); + jQuery('#jform_field_type').prop('required','required'); + jQuery('#jform_field_type').attr('aria-required',true); + jQuery('#jform_field_type').addClass('required'); + jform_vvvvvvyvvz_required = false; + } + jQuery('#jform_edit_relationship').closest('.control-group').show(); + // add required attribute to edit_relationship field + if (jform_vvvvvvyvwa_required) + { + updateFieldRequired('edit_relationship',0); + jQuery('#jform_edit_relationship').prop('required','required'); + jQuery('#jform_edit_relationship').attr('aria-required',true); + jQuery('#jform_edit_relationship').addClass('required'); + jform_vvvvvvyvwa_required = false; + } + jQuery('#jform_type').closest('.control-group').show(); + // add required attribute to type field + if (jform_vvvvvvyvwb_required) + { + updateFieldRequired('type',0); + jQuery('#jform_type').prop('required','required'); + jQuery('#jform_type').attr('aria-required',true); + jQuery('#jform_type').addClass('required'); + jform_vvvvvvyvwb_required = false; + } + jQuery('#jform_view_relationship').closest('.control-group').show(); + // add required attribute to view_relationship field + if (jform_vvvvvvyvwc_required) + { + updateFieldRequired('view_relationship',0); + jQuery('#jform_view_relationship').prop('required','required'); + jQuery('#jform_view_relationship').attr('aria-required',true); + jQuery('#jform_view_relationship').addClass('required'); + jform_vvvvvvyvwc_required = false; + } + } + else + { + jQuery('#jform_communicate').closest('.control-group').hide(); + jQuery('#jform_field_type').closest('.control-group').hide(); + // remove required attribute from field_type field + if (!jform_vvvvvvyvvz_required) + { + updateFieldRequired('field_type',1); + jQuery('#jform_field_type').removeAttr('required'); + jQuery('#jform_field_type').removeAttr('aria-required'); + jQuery('#jform_field_type').removeClass('required'); + jform_vvvvvvyvvz_required = true; + } + jQuery('#jform_edit_relationship').closest('.control-group').hide(); + // remove required attribute from edit_relationship field + if (!jform_vvvvvvyvwa_required) + { + updateFieldRequired('edit_relationship',1); + jQuery('#jform_edit_relationship').removeAttr('required'); + jQuery('#jform_edit_relationship').removeAttr('aria-required'); + jQuery('#jform_edit_relationship').removeClass('required'); + jform_vvvvvvyvwa_required = true; + } + jQuery('#jform_type').closest('.control-group').hide(); + // remove required attribute from type field + if (!jform_vvvvvvyvwb_required) + { + updateFieldRequired('type',1); + jQuery('#jform_type').removeAttr('required'); + jQuery('#jform_type').removeAttr('aria-required'); + jQuery('#jform_type').removeClass('required'); + jform_vvvvvvyvwb_required = true; + } + jQuery('#jform_view_relationship').closest('.control-group').hide(); + // remove required attribute from view_relationship field + if (!jform_vvvvvvyvwc_required) + { + updateFieldRequired('view_relationship',1); + jQuery('#jform_view_relationship').removeAttr('required'); + jQuery('#jform_view_relationship').removeAttr('aria-required'); + jQuery('#jform_view_relationship').removeClass('required'); + jform_vvvvvvyvwc_required = true; + } + } +} + +// update required fields +function updateFieldRequired(name,status) +{ + var not_required = jQuery('#jform_not_required').val(); + + if(status == 1) + { + if (isSet(not_required) && not_required != 0) + { + not_required = not_required+','+name; + } + else + { + not_required = ','+name; + } + } + else + { + if (isSet(not_required) && not_required != 0) + { + not_required = not_required.replace(','+name,''); + } + } + + jQuery('#jform_not_required').val(not_required); +} + +// the isSet function +function isSet(val) +{ + if ((val != undefined) && (val != null) && 0 !== val.length){ + return true; + } + return false; +} diff --git a/admin/models/forms/type.xml b/admin/models/forms/type.xml index d33fc83..9ecbd9d 100644 --- a/admin/models/forms/type.xml +++ b/admin/models/forms/type.xml @@ -131,6 +131,86 @@ required="true" multiple="true" /> + + + + + + + + + + + + + + + + + + + + + + + + + * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/models/member.php b/admin/models/member.php index c95c87f..ef1eff6 100644 --- a/admin/models/member.php +++ b/admin/models/member.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -97,6 +97,14 @@ class MembersmanagerModelMember extends JModelAdmin $item->profile_image = rtrim($medium->decryptString($item->profile_image), "\0"); } + if (!empty($item->type)) + { + // Convert the type field to an array. + $type = new Registry; + $type->loadString($item->type); + $item->type = $type->toArray(); + } + if (empty($item->id)) { @@ -245,12 +253,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('name', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('name')) + if (!($val = $form->getValue('name'))) { // Disable fields while saving. $form->setFieldAttribute('name', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('name', 'required', 'false'); + // Make sure + $form->setValue('name', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('name'); } } // Modify the form based on Edit Email access controls. @@ -284,12 +301,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('email', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('email')) + if (!($val = $form->getValue('email'))) { // Disable fields while saving. $form->setFieldAttribute('email', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('email', 'required', 'false'); + // Make sure + $form->setValue('email', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('email'); } } // Modify the form based on Edit Account access controls. @@ -316,12 +342,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('account', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('account')) + if (!($val = $form->getValue('account'))) { // Disable fields while saving. $form->setFieldAttribute('account', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('account', 'required', 'false'); + // Make sure + $form->setValue('account', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('account'); } } // Modify the form based on Edit User access controls. @@ -348,12 +383,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('user', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('user')) + if (!($val = $form->getValue('user'))) { // Disable fields while saving. $form->setFieldAttribute('user', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('user', 'required', 'false'); + // Make sure + $form->setValue('user', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('user'); } } // Modify the form based on Edit Token access controls. @@ -380,12 +424,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('token', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('token')) + if (!($val = $form->getValue('token'))) { // Disable fields while saving. $form->setFieldAttribute('token', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('token', 'required', 'false'); + // Make sure + $form->setValue('token', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('token'); } } // Modify the form based on Edit Profile Image access controls. @@ -419,12 +472,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('profile_image', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('profile_image')) + if (!($val = $form->getValue('profile_image'))) { // Disable fields while saving. $form->setFieldAttribute('profile_image', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('profile_image', 'required', 'false'); + // Make sure + $form->setValue('profile_image', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('profile_image'); } } // Modify the form based on Edit Main Member access controls. @@ -451,12 +513,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('main_member', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('main_member')) + if (!($val = $form->getValue('main_member'))) { // Disable fields while saving. $form->setFieldAttribute('main_member', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('main_member', 'required', 'false'); + // Make sure + $form->setValue('main_member', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('main_member'); } } // Modify the form based on Edit Password Check access controls. @@ -490,12 +561,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('password_check', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('password_check')) + if (!($val = $form->getValue('password_check'))) { // Disable fields while saving. $form->setFieldAttribute('password_check', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('password_check', 'required', 'false'); + // Make sure + $form->setValue('password_check', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('password_check'); } } // Modify the form based on Edit Password access controls. @@ -529,12 +609,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('password', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('password')) + if (!($val = $form->getValue('password'))) { // Disable fields while saving. $form->setFieldAttribute('password', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('password', 'required', 'false'); + // Make sure + $form->setValue('password', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('password'); } } // Modify the form based on Edit Useremail access controls. @@ -568,12 +657,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('useremail', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('useremail')) + if (!($val = $form->getValue('useremail'))) { // Disable fields while saving. $form->setFieldAttribute('useremail', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('useremail', 'required', 'false'); + // Make sure + $form->setValue('useremail', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('useremail'); } } // Modify the form based on Edit Username access controls. @@ -607,12 +705,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('username', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('username')) + if (!($val = $form->getValue('username'))) { // Disable fields while saving. $form->setFieldAttribute('username', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('username', 'required', 'false'); + // Make sure + $form->setValue('username', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('username'); } } // Modify the form based on Edit Surname access controls. @@ -639,12 +746,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('surname', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('surname')) + if (!($val = $form->getValue('surname'))) { // Disable fields while saving. $form->setFieldAttribute('surname', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('surname', 'required', 'false'); + // Make sure + $form->setValue('surname', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('surname'); } } // Modify the form based on Edit Type access controls. @@ -671,12 +787,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('type', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('type')) + if (!($val = $form->getValue('type'))) { // Disable fields while saving. $form->setFieldAttribute('type', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('type', 'required', 'false'); + // Make sure + $form->setValue('type', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('type'); } } // Only load these values if no id is found @@ -925,10 +1050,66 @@ class MembersmanagerModelMember extends JModelAdmin * @since 12.2 */ public function delete(&$pks) - { + { + // check if member is still linked to other sub members as a main member + if (MembersmanagerHelper::checkArray($pks)) + { + // get the application object + $app = JFactory::getApplication(); + // now loop the ids + foreach ($pks as $key => $pk) + { + // check if member still have sub accounts linked to it + if (($found = MembersmanagerHelper::getVar('member', $pk, 'main_member', 'id')) !== false) + { + // set the name + $name = MembersmanagerHelper::getMemberName($pk); + // set a message + $app->enqueueMessage(JText::sprintf('COM_MEMBERSMANAGER_YOU_CAN_NOT_DELETE_BSB_FIRST_MOVE_ALL_SUB_ACCOUNTS_TO_NEW_MAIN_MEMBER', $name), 'Error'); + // remove for the list + unset($pks[$key]); + } + } + } if (!parent::delete($pks)) { return false; + } + + // we must also update all linked tables + if (MembersmanagerHelper::checkArray($pks)) + { + $seek = array('Info', 'Assessment'); + foreach ($seek as $area) + { + if (($components = MembersmanagerHelper::{'get' . $area . 'Components'}()) !== false) + { + foreach($components as $_component) + { + $component = str_replace('com_', '', $_component->element); + $Component = MembersmanagerHelper::safeString($component, 'F'); + // get the linked IDs + if (($ids = MembersmanagerHelper::getVars('form', $pks, 'member', 'id', 'IN', $component)) !== false && MembersmanagerHelper::checkArray($ids)) + { + // get the model + $_Model = MembersmanagerHelper::getModel('form', JPATH_ADMINISTRATOR . '/components/' . $_component->element, $Component); + // do we have the model + if ($_Model) + { + // change publish state + $_Model->delete($ids); + } + } + } + } + } + // now loop the ids + foreach ($pks as $key => $pk) + { + // make sure to remove the type_map + MembersmanagerHelper::updateTypes($pk); + // must still do the relationship clearing (TODO) + } } return true; @@ -949,6 +1130,35 @@ class MembersmanagerModelMember extends JModelAdmin if (!parent::publish($pks, $value)) { return false; + } + + // we must also update all linked tables + if (MembersmanagerHelper::checkArray($pks)) + { + $seek = array('Info', 'Assessment'); + foreach ($seek as $area) + { + if (($components = MembersmanagerHelper::{'get' . $area . 'Components'}()) !== false) + { + foreach($components as $_component) + { + $component = str_replace('com_', '', $_component->element); + $Component = MembersmanagerHelper::safeString($component, 'F'); + // get the linked IDs + if (($ids = MembersmanagerHelper::getVars('form', $pks, 'member', 'id', 'IN', $component)) !== false && MembersmanagerHelper::checkArray($ids)) + { + // get the model + $_Model = MembersmanagerHelper::getModel('form', JPATH_ADMINISTRATOR . '/components/' . $_component->element, $Component); + // do we have the model + if ($_Model) + { + // change publish state + $_Model->publish($ids, $value); + } + } + } + } + } } return true; @@ -1325,16 +1535,39 @@ class MembersmanagerModelMember extends JModelAdmin $data['metadata'] = (string) $metadata; } + // get user object + $user = JFactory::getUser(); + // set ID + $id = (isset($data['id']) && $data['id'] > 0) ? $data['id'] : false; + // little function to check user access + $checkUserAccess = function ($permission) use($user, $id) { + return (($id && $user->authorise('member.' . $permission, 'com_membersmanager.member.' . (int) $id)) || (!$id && $user->authorise('member.' . $permission, 'com_membersmanager'))); + }; + // make sure these type is set + if ($id && !$checkUserAccess('edit.type')) + { + $data['type'] = MembersmanagerHelper::getVar('member', $id, 'id', 'type'); + } + // make sure these account is set + if ($id && !$checkUserAccess('edit.account')) + { + $data['account'] = MembersmanagerHelper::getVar('member', $id, 'id', 'account'); + } + // get user value if not set (due to permissions) + if ($id && isset($data['account']) && (1 == $data['account'] || 4 == $data['account']) && (!isset($data['user']) || $data['user'] == 0)) + { + $data['user'] = MembersmanagerHelper::getVar('member', $id, 'id', 'user'); + } // check if this is a linked user (MUST STILL DO PERMISSIONS) - if (isset($data['account']) && (1 == $data['account'] || 4 == $data['account'])) + if (isset($data['account']) && (1 == $data['account'] || 4 == $data['account']) && $checkUserAccess('edit.user')) { // get the application object $app = JFactory::getApplication(); // check if member already exist - if (isset($data['id']) && $data['id'] > 0 && isset($data['user']) && $data['user'] > 0) + if ($id && isset($data['user']) && $data['user'] > 0) { // do not allow user link to be changed (should have done this in the controller) - if (($alreadyUser = MembersmanagerHelper::getVar('member', $data['id'], 'id', 'user')) !== false && is_numeric($alreadyUser) && $alreadyUser > 0 && $alreadyUser != $data['user']) + if (($alreadyUser = MembersmanagerHelper::getVar('member', $id, 'id', 'user')) !== false && is_numeric($alreadyUser) && $alreadyUser > 0 && $alreadyUser != $data['user']) { $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_MEMBER_IS_ALREADY_LINKED_TO_AN_USER_THIS_CAN_NOT_BE_CHANGED_CONTACT_YOUR_SYSTEM_ADMINISTRATOR_IF_YOU_NEED_MORE_HELP'), 'Error'); return false; @@ -1355,27 +1588,17 @@ class MembersmanagerModelMember extends JModelAdmin { // set user ID $bucket['id'] = $data['user']; - // get user exciting groups + // get member user $memberUser = JFactory::getUser($bucket['id']); - $excitingGroups = $memberUser->get('groups'); - $typeGroups = array(); - // set the groups - if (isset($data['type']) && $data['type'] > 0) - { - // get the target groups - $typeGroups = MembersmanagerHelper::getVar('type', $data['type'], 'id', 'groups_target'); - // convert to array - if (MembersmanagerHelper::checkJson($typeGroups)) - { - $typeGroups = (array) json_decode($typeGroups, true); - } - elseif (is_numeric($typeGroups)) - { - $typeGroups = array((int) $typeGroups); - } - } + // get user exciting groups + $bucket['groups'] = $memberUser->get('groups'); + // remove all groups part of members manager + MembersmanagerHelper::removeMemberGroups($bucket['groups']); // load the user groups (TODO) - $bucket['groups'] = MembersmanagerHelper::mergeArrays(array($excitingGroups, $typeGroups)); + if (($typeGroups = MembersmanagerHelper::getMemberGroupsByType($data['type'])) !== false) + { + $bucket['groups'] = MembersmanagerHelper::mergeArrays(array($bucket['groups'], $typeGroups)); + } // set password if (empty($data['password']) || empty($data['password_check'])) { @@ -1413,25 +1636,11 @@ class MembersmanagerModelMember extends JModelAdmin { // make sure to set the user value $data['user'] = $done; - if (isset($data['type']) && $data['type'] > 0) - { - // get the target groups - $_groups = MembersmanagerHelper::getVar('type', $data['type'], 'id', 'groups_target'); - // convert to array - if (MembersmanagerHelper::checkJson($_groups)) - { - $groups = (array) json_decode($_groups, true); - } - elseif (is_numeric($_groups)) - { - $groups = array((int) $_groups); - } - } // check if we have groups - if (isset($groups) && $groups) + if (($typeGroups = MembersmanagerHelper::getMemberGroupsByType($data['type'])) !== false) { // update the user groups - JUserHelper::setUserGroups((int) $done ,(array) $groups); + JUserHelper::setUserGroups((int) $done, (array) $typeGroups); } else { @@ -1450,12 +1659,25 @@ class MembersmanagerModelMember extends JModelAdmin $data['user'] = $didCreate; } } + // check if the user was set + if (isset($data['user']) && $data['user'] > 0) + { + // the login member must always own it self for edit permissions + $data['created_by'] = $data['user']; + } + } + // if a sub account and not login access + if (isset($data['account']) && 3 == $data['account'] && isset($data['main_member']) && $data['main_member'] > 0 + && ($mainMemberUser = MembersmanagerHelper::getVar('member', $data['main_member'], 'id', 'user')) !== false && $mainMemberUser > 0) + { + // the main user must always own it self for edit permissions + $data['created_by'] = $mainMemberUser; } // always clear out password!! unset($data['password']); unset($data['password_check']); // clear out user if error found - if (empty($data['user']) || $data['user'] == 0 || empty($data['account']) || (1 != $data['account'] && 4 != $data['account'])) + if ((empty($data['user']) || $data['user'] == 0 || empty($data['account']) || (1 != $data['account'] && 4 != $data['account'])) && $checkUserAccess('edit.user') && $checkUserAccess('edit.account')) { // if not a linked account, then no user can be set $data['user'] = ''; @@ -1468,7 +1690,7 @@ class MembersmanagerModelMember extends JModelAdmin // get a token $token = call_user_func(function($data) { // get the name of this member - if ((1 == $data['account'] || 4 == $data['account']) && isset($data['user']) && $data['user'] > 0) + if (isset($data['account']) && (1 == $data['account'] || 4 == $data['account']) && isset($data['user']) && $data['user'] > 0) { return JFactory::getUser($data['user'])->name; } @@ -1483,12 +1705,29 @@ class MembersmanagerModelMember extends JModelAdmin // make string safe $data['token'] = MembersmanagerHelper::safeString(trim(implode(' ', $tokenArray), '-'), 'L', '-', false, false); // get unique token - while (!MembersmanagerHelper::checkUnique($data['id'], 'token', $data['token'], 'member')) + while (!MembersmanagerHelper::checkUnique($id, 'token', $data['token'], 'member')) { $data['token'] = JString::increment($data['token'], 'dash'); } } + // Set the type items to data. + if (isset($data['type']) && is_array($data['type'])) + { + $type = new JRegistry; + $type->loadArray($data['type']); + $data['type'] = (string) $type; + } + // Also check permission since the value may be removed due to permissions + // Then we do not want to clear it out, but simple ignore the empty type + elseif (!isset($data['type']) + && JFactory::getUser()->authorise('member.edit.type', 'com_membersmanager') + && JFactory::getUser()->authorise('member.view.type', 'com_membersmanager')) + { + // Set the empty type to data + $data['type'] = ''; + } + // Get the medium encryption key. $mediumkey = MembersmanagerHelper::getCryptKey('medium'); // Get the encryption object diff --git a/admin/models/members.php b/admin/models/members.php index da104a1..13ab7db 100644 --- a/admin/models/members.php +++ b/admin/models/members.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -28,8 +28,7 @@ class MembersmanagerModelMembers extends JModelList 'a.created_by','created_by', 'a.modified_by','modified_by', 'a.account','account', - 'a.main_member','main_member', - 'a.type','type' + 'a.main_member','main_member' ); } @@ -54,10 +53,7 @@ class MembersmanagerModelMembers extends JModelList $this->setState('filter.account', $account); $main_member = $this->getUserStateFromRequest($this->context . '.filter.main_member', 'filter_main_member'); - $this->setState('filter.main_member', $main_member); - - $type = $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type'); - $this->setState('filter.type', $type); + $this->setState('filter.main_member', $main_member); $sorting = $this->getUserStateFromRequest($this->context . '.filter.sorting', 'filter_sorting', 0, 'int'); $this->setState('filter.sorting', $sorting); @@ -118,6 +114,8 @@ class MembersmanagerModelMembers extends JModelList { $item->email = JFactory::getUser($item->user)->email; } + // convert type + $item->type = MembersmanagerHelper::jsonToString($item->type, ', ', 'type', 'id', 'name'); } } @@ -238,7 +236,7 @@ class MembersmanagerModelMembers extends JModelList else { $search = $db->quote('%' . $db->escape($search) . '%'); - $query->where('(a.name LIKE '.$search.' OR a.email LIKE '.$search.' OR a.account LIKE '.$search.' OR a.user LIKE '.$search.' OR a.token LIKE '.$search.' OR a.main_member LIKE '.$search.' OR a.useremail LIKE '.$search.' OR a.username LIKE '.$search.' OR a.surname LIKE '.$search.' OR a.type LIKE '.$search.')'); + $query->where('(a.name LIKE '.$search.' OR a.email LIKE '.$search.' OR a.account LIKE '.$search.' OR a.user LIKE '.$search.' OR a.token LIKE '.$search.' OR a.main_member LIKE '.$search.' OR a.useremail LIKE '.$search.' OR a.username LIKE '.$search.' OR a.surname LIKE '.$search.')'); } } @@ -252,11 +250,6 @@ class MembersmanagerModelMembers extends JModelList { $query->where('a.main_member = ' . $db->quote($db->escape($main_member))); } - // Filter by type. - if ($type = $this->getState('filter.type')) - { - $query->where('a.type = ' . $db->quote($db->escape($type))); - } // Add the list ordering clause. $orderCol = $this->state->get('list.ordering', 'a.id'); @@ -415,8 +408,7 @@ class MembersmanagerModelMembers extends JModelList $id .= ':' . $this->getState('filter.created_by'); $id .= ':' . $this->getState('filter.modified_by'); $id .= ':' . $this->getState('filter.account'); - $id .= ':' . $this->getState('filter.main_member'); - $id .= ':' . $this->getState('filter.type'); + $id .= ':' . $this->getState('filter.main_member'); return parent::getStoreId($id); } diff --git a/admin/models/rules/memberloginname.php b/admin/models/rules/memberloginname.php index a74e327..702a113 100644 --- a/admin/models/rules/memberloginname.php +++ b/admin/models/rules/memberloginname.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/models/rules/memberuseremail.php b/admin/models/rules/memberuseremail.php index f0f51cd..5179535 100644 --- a/admin/models/rules/memberuseremail.php +++ b/admin/models/rules/memberuseremail.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/models/rules/uniquefield.php b/admin/models/rules/uniquefield.php index 97acef4..b02075d 100644 --- a/admin/models/rules/uniquefield.php +++ b/admin/models/rules/uniquefield.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/models/type.php b/admin/models/type.php index a38ddb4..c315f3e 100644 --- a/admin/models/type.php +++ b/admin/models/type.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -81,6 +81,30 @@ class MembersmanagerModelType extends JModelAdmin $item->metadata = $registry->toArray(); } + if (!empty($item->view_relationship)) + { + // Convert the view_relationship field to an array. + $view_relationship = new Registry; + $view_relationship->loadString($item->view_relationship); + $item->view_relationship = $view_relationship->toArray(); + } + + if (!empty($item->edit_relationship)) + { + // Convert the edit_relationship field to an array. + $edit_relationship = new Registry; + $edit_relationship->loadString($item->edit_relationship); + $item->edit_relationship = $edit_relationship->toArray(); + } + + if (!empty($item->type)) + { + // Convert the type field to an array. + $type = new Registry; + $type->loadString($item->type); + $item->type = $type->toArray(); + } + if (!empty($item->groups_target)) { // JSON Decode groups_target. @@ -247,6 +271,114 @@ class MembersmanagerModelType extends JModelAdmin $form->setFieldAttribute('groups_access', 'required', 'false'); } } + // Modify the form based on Edit Add Relationship access controls. + if ($id != 0 && (!$user->authorise('type.edit.add_relationship', 'com_membersmanager.type.' . (int) $id)) + || ($id == 0 && !$user->authorise('type.edit.add_relationship', 'com_membersmanager'))) + { + // Disable fields for display. + $form->setFieldAttribute('add_relationship', 'disabled', 'true'); + // Disable fields for display. + $form->setFieldAttribute('add_relationship', 'readonly', 'true'); + // Disable radio button for display. + $class = $form->getFieldAttribute('add_relationship', 'class', ''); + $form->setFieldAttribute('add_relationship', 'class', $class.' disabled no-click'); + // If there is no value continue. + if (!$form->getValue('add_relationship')) + { + // Disable fields while saving. + $form->setFieldAttribute('add_relationship', 'filter', 'unset'); + // Disable fields while saving. + $form->setFieldAttribute('add_relationship', 'required', 'false'); + } + } + // Modify the form based on Edit Field Type access controls. + if ($id != 0 && (!$user->authorise('type.edit.field_type', 'com_membersmanager.type.' . (int) $id)) + || ($id == 0 && !$user->authorise('type.edit.field_type', 'com_membersmanager'))) + { + // Disable fields for display. + $form->setFieldAttribute('field_type', 'disabled', 'true'); + // Disable fields for display. + $form->setFieldAttribute('field_type', 'readonly', 'true'); + // If there is no value continue. + if (!$form->getValue('field_type')) + { + // Disable fields while saving. + $form->setFieldAttribute('field_type', 'filter', 'unset'); + // Disable fields while saving. + $form->setFieldAttribute('field_type', 'required', 'false'); + } + } + // Modify the form based on Edit Communicate access controls. + if ($id != 0 && (!$user->authorise('type.edit.communicate', 'com_membersmanager.type.' . (int) $id)) + || ($id == 0 && !$user->authorise('type.edit.communicate', 'com_membersmanager'))) + { + // Disable fields for display. + $form->setFieldAttribute('communicate', 'disabled', 'true'); + // Disable fields for display. + $form->setFieldAttribute('communicate', 'readonly', 'true'); + // Disable radio button for display. + $class = $form->getFieldAttribute('communicate', 'class', ''); + $form->setFieldAttribute('communicate', 'class', $class.' disabled no-click'); + // If there is no value continue. + if (!$form->getValue('communicate')) + { + // Disable fields while saving. + $form->setFieldAttribute('communicate', 'filter', 'unset'); + // Disable fields while saving. + $form->setFieldAttribute('communicate', 'required', 'false'); + } + } + // Modify the form based on Edit View Relationship access controls. + if ($id != 0 && (!$user->authorise('type.edit.view_relationship', 'com_membersmanager.type.' . (int) $id)) + || ($id == 0 && !$user->authorise('type.edit.view_relationship', 'com_membersmanager'))) + { + // Disable fields for display. + $form->setFieldAttribute('view_relationship', 'disabled', 'true'); + // Disable fields for display. + $form->setFieldAttribute('view_relationship', 'readonly', 'true'); + // If there is no value continue. + if (!$form->getValue('view_relationship')) + { + // Disable fields while saving. + $form->setFieldAttribute('view_relationship', 'filter', 'unset'); + // Disable fields while saving. + $form->setFieldAttribute('view_relationship', 'required', 'false'); + } + } + // Modify the form based on Edit Edit Relationship access controls. + if ($id != 0 && (!$user->authorise('type.edit.edit_relationship', 'com_membersmanager.type.' . (int) $id)) + || ($id == 0 && !$user->authorise('type.edit.edit_relationship', 'com_membersmanager'))) + { + // Disable fields for display. + $form->setFieldAttribute('edit_relationship', 'disabled', 'true'); + // Disable fields for display. + $form->setFieldAttribute('edit_relationship', 'readonly', 'true'); + // If there is no value continue. + if (!$form->getValue('edit_relationship')) + { + // Disable fields while saving. + $form->setFieldAttribute('edit_relationship', 'filter', 'unset'); + // Disable fields while saving. + $form->setFieldAttribute('edit_relationship', 'required', 'false'); + } + } + // Modify the form based on Edit Type access controls. + if ($id != 0 && (!$user->authorise('type.edit.type', 'com_membersmanager.type.' . (int) $id)) + || ($id == 0 && !$user->authorise('type.edit.type', 'com_membersmanager'))) + { + // Disable fields for display. + $form->setFieldAttribute('type', 'disabled', 'true'); + // Disable fields for display. + $form->setFieldAttribute('type', 'readonly', 'true'); + // If there is no value continue. + if (!$form->getValue('type')) + { + // Disable fields while saving. + $form->setFieldAttribute('type', 'filter', 'unset'); + // Disable fields while saving. + $form->setFieldAttribute('type', 'required', 'false'); + } + } // Only load these values if no id is found if (0 == $id) { @@ -424,6 +556,42 @@ class MembersmanagerModelType extends JModelAdmin return $data; } + /** + * Method to validate the form data. + * + * @param JForm $form The form to validate against. + * @param array $data The data to validate. + * @param string $group The name of the field group to validate. + * + * @return mixed Array of filtered data if valid, false otherwise. + * + * @see JFormRule + * @see JFilterInput + * @since 12.2 + */ + public function validate($form, $data, $group = null) + { + // check if the not_required field is set + if (MembersmanagerHelper::checkString($data['not_required'])) + { + $requiredFields = (array) explode(',',(string) $data['not_required']); + $requiredFields = array_unique($requiredFields); + // now change the required field attributes value + foreach ($requiredFields as $requiredField) + { + // make sure there is a string value + if (MembersmanagerHelper::checkString($requiredField)) + { + // change to false + $form->setFieldAttribute($requiredField, 'required', 'false'); + // also clear the data set + $data[$requiredField] = ''; + } + } + } + return parent::validate($form, $data, $group); + } + /** * Method to get the unique fields of this table. * @@ -841,6 +1009,54 @@ class MembersmanagerModelType extends JModelAdmin $data['metadata'] = (string) $metadata; } + // Set the view_relationship items to data. + if (isset($data['view_relationship']) && is_array($data['view_relationship'])) + { + $view_relationship = new JRegistry; + $view_relationship->loadArray($data['view_relationship']); + $data['view_relationship'] = (string) $view_relationship; + } + // Also check permission since the value may be removed due to permissions + // Then we do not want to clear it out, but simple ignore the empty view_relationship + elseif (!isset($data['view_relationship']) + && JFactory::getUser()->authorise('type.edit.view_relationship', 'com_membersmanager')) + { + // Set the empty view_relationship to data + $data['view_relationship'] = ''; + } + + // Set the edit_relationship items to data. + if (isset($data['edit_relationship']) && is_array($data['edit_relationship'])) + { + $edit_relationship = new JRegistry; + $edit_relationship->loadArray($data['edit_relationship']); + $data['edit_relationship'] = (string) $edit_relationship; + } + // Also check permission since the value may be removed due to permissions + // Then we do not want to clear it out, but simple ignore the empty edit_relationship + elseif (!isset($data['edit_relationship']) + && JFactory::getUser()->authorise('type.edit.edit_relationship', 'com_membersmanager')) + { + // Set the empty edit_relationship to data + $data['edit_relationship'] = ''; + } + + // Set the type items to data. + if (isset($data['type']) && is_array($data['type'])) + { + $type = new JRegistry; + $type->loadArray($data['type']); + $data['type'] = (string) $type; + } + // Also check permission since the value may be removed due to permissions + // Then we do not want to clear it out, but simple ignore the empty type + elseif (!isset($data['type']) + && JFactory::getUser()->authorise('type.edit.type', 'com_membersmanager')) + { + // Set the empty type to data + $data['type'] = ''; + } + // Set the groups_target string to JSON string. if (isset($data['groups_target'])) { diff --git a/admin/models/types.php b/admin/models/types.php index d19d1f4..7ab44da 100644 --- a/admin/models/types.php +++ b/admin/models/types.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -27,7 +27,8 @@ class MembersmanagerModelTypes extends JModelList 'a.ordering','ordering', 'a.created_by','created_by', 'a.modified_by','modified_by', - 'a.name','name' + 'a.name','name', + 'a.add_relationship','add_relationship' ); } @@ -49,7 +50,10 @@ class MembersmanagerModelTypes extends JModelList $this->context .= '.' . $layout; } $name = $this->getUserStateFromRequest($this->context . '.filter.name', 'filter_name'); - $this->setState('filter.name', $name); + $this->setState('filter.name', $name); + + $add_relationship = $this->getUserStateFromRequest($this->context . '.filter.add_relationship', 'filter_add_relationship'); + $this->setState('filter.add_relationship', $add_relationship); $sorting = $this->getUserStateFromRequest($this->context . '.filter.sorting', 'filter_sorting', 0, 'int'); $this->setState('filter.sorting', $sorting); @@ -139,10 +143,44 @@ class MembersmanagerModelTypes extends JModelList $item->groups_access = $groups_accessNames; } } - } + } + + // set selection value to a translatable value + if (MembersmanagerHelper::checkArray($items)) + { + foreach ($items as $nr => &$item) + { + // convert add_relationship + $item->add_relationship = $this->selectionTranslation($item->add_relationship, 'add_relationship'); + } + } + // return items return $items; + } + + /** + * Method to convert selection values to translatable string. + * + * @return translatable string + */ + public function selectionTranslation($value,$name) + { + // Array of add_relationship language strings + if ($name === 'add_relationship') + { + $add_relationshipArray = array( + 1 => 'COM_MEMBERSMANAGER_TYPE_YES', + 0 => 'COM_MEMBERSMANAGER_TYPE_NO' + ); + // Now check if value is found in this array + if (isset($add_relationshipArray[$value]) && MembersmanagerHelper::checkString($add_relationshipArray[$value])) + { + return $add_relationshipArray[$value]; + } + } + return $value; } /** @@ -204,6 +242,11 @@ class MembersmanagerModelTypes extends JModelList } } + // Filter by Add_relationship. + if ($add_relationship = $this->getState('filter.add_relationship')) + { + $query->where('a.add_relationship = ' . $db->quote($db->escape($add_relationship))); + } // Add the list ordering clause. $orderCol = $this->state->get('list.ordering', 'a.id'); @@ -329,7 +372,8 @@ class MembersmanagerModelTypes extends JModelList $id .= ':' . $this->getState('filter.ordering'); $id .= ':' . $this->getState('filter.created_by'); $id .= ':' . $this->getState('filter.modified_by'); - $id .= ':' . $this->getState('filter.name'); + $id .= ':' . $this->getState('filter.name'); + $id .= ':' . $this->getState('filter.add_relationship'); return parent::getStoreId($id); } diff --git a/admin/sql/install.mysql.utf8.sql b/admin/sql/install.mysql.utf8.sql index feec1e9..bc9db0c 100644 --- a/admin/sql/install.mysql.utf8.sql +++ b/admin/sql/install.mysql.utf8.sql @@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS `#__membersmanager_member` ( `profile_image` TEXT NOT NULL, `surname` CHAR(255) NOT NULL DEFAULT '', `token` VARCHAR(255) NOT NULL DEFAULT '', - `type` INT(11) NOT NULL DEFAULT 0, + `type` TEXT NOT NULL, `user` INT(11) NOT NULL DEFAULT 0, `useremail` VARCHAR(255) NOT NULL DEFAULT '', `username` VARCHAR(255) NOT NULL DEFAULT '', @@ -41,11 +41,17 @@ CREATE TABLE IF NOT EXISTS `#__membersmanager_member` ( CREATE TABLE IF NOT EXISTS `#__membersmanager_type` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `asset_id` INT(10) unsigned NOT NULL DEFAULT 0 COMMENT 'FK to the #__assets table.', + `add_relationship` TINYINT(1) NOT NULL DEFAULT 0, `alias` CHAR(64) NOT NULL DEFAULT '', + `communicate` TINYINT(1) NOT NULL DEFAULT 0, `description` TEXT NOT NULL, + `edit_relationship` TEXT NOT NULL, + `field_type` TINYINT(1) NOT NULL DEFAULT 1, `groups_access` TEXT NOT NULL, `groups_target` TEXT NOT NULL, `name` VARCHAR(255) NOT NULL DEFAULT '', + `type` TEXT NOT NULL, + `view_relationship` TEXT NOT NULL, `params` text NOT NULL DEFAULT '', `published` TINYINT(3) NOT NULL DEFAULT 1, `created_by` INT(10) unsigned NOT NULL DEFAULT 0, @@ -65,9 +71,23 @@ CREATE TABLE IF NOT EXISTS `#__membersmanager_type` ( KEY `idx_modifiedby` (`modified_by`), KEY `idx_state` (`published`), KEY `idx_name` (`name`), + KEY `idx_add_relationship` (`add_relationship`), + KEY `idx_field_type` (`field_type`), + KEY `idx_communicate` (`communicate`), KEY `idx_alias` (`alias`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; +CREATE TABLE IF NOT EXISTS `#__membersmanager_type_map` ( + `member` INT(11) NOT NULL DEFAULT 0, + `type` INT(11) NOT NULL DEFAULT 0 +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `#__membersmanager_relation_map` ( + `relation` INT(11) NOT NULL DEFAULT 0, + `member` INT(11) NOT NULL DEFAULT 0, + `type` INT(11) NOT NULL DEFAULT 0 +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + -- diff --git a/admin/sql/uninstall.mysql.utf8.sql b/admin/sql/uninstall.mysql.utf8.sql index 4bd0949..af2ad0e 100644 --- a/admin/sql/uninstall.mysql.utf8.sql +++ b/admin/sql/uninstall.mysql.utf8.sql @@ -1,2 +1,4 @@ DROP TABLE IF EXISTS `#__membersmanager_member`; DROP TABLE IF EXISTS `#__membersmanager_type`; +DROP TABLE IF EXISTS `#__membersmanager_type_map`; +DROP TABLE IF EXISTS `#__membersmanager_relation_map`; diff --git a/admin/sql/updates/mysql/2.0.1.sql b/admin/sql/updates/mysql/2.0.1.sql new file mode 100644 index 0000000..60e6c43 --- /dev/null +++ b/admin/sql/updates/mysql/2.0.1.sql @@ -0,0 +1 @@ +ALTER TABLE `#__membersmanager_member` CHANGE `type` `type` VARCHAR(255) NOT NULL DEFAULT ''; diff --git a/admin/sql/updates/mysql/2.0.2.sql b/admin/sql/updates/mysql/2.0.2.sql new file mode 100644 index 0000000..f20ff6d --- /dev/null +++ b/admin/sql/updates/mysql/2.0.2.sql @@ -0,0 +1 @@ +ALTER TABLE `#__membersmanager_member` CHANGE `type` `type` TEXT NOT NULL; diff --git a/admin/sql/updates/mysql/2.0.3.sql b/admin/sql/updates/mysql/2.0.3.sql new file mode 100644 index 0000000..6280529 --- /dev/null +++ b/admin/sql/updates/mysql/2.0.3.sql @@ -0,0 +1,3 @@ +ALTER TABLE `#__membersmanager_type` ADD `add_relationship` TINYINT(1) NOT NULL DEFAULT 0 AFTER `asset_id`; + +ALTER TABLE `#__membersmanager_type` ADD `type` TEXT NOT NULL AFTER `name`; diff --git a/admin/sql/updates/mysql/2.0.4.sql b/admin/sql/updates/mysql/2.0.4.sql new file mode 100644 index 0000000..7500b1f --- /dev/null +++ b/admin/sql/updates/mysql/2.0.4.sql @@ -0,0 +1,14 @@ +ALTER TABLE `#__membersmanager_type` ADD `communicate` TINYINT(1) NOT NULL DEFAULT 0 AFTER `alias`; + +ALTER TABLE `#__membersmanager_type` ADD `field_type` TINYINT(1) NOT NULL DEFAULT 1 AFTER `description`; + +CREATE TABLE IF NOT EXISTS `#__membersmanager_type_map` ( + `member` INT(11) NOT NULL DEFAULT 0, + `type` INT(11) NOT NULL DEFAULT 0 +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `#__membersmanager_relation_map` ( + `relation` INT(11) NOT NULL DEFAULT 0, + `member` INT(11) NOT NULL DEFAULT 0, + `type` INT(11) NOT NULL DEFAULT 0 +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; diff --git a/admin/sql/updates/mysql/2.0.5.sql b/admin/sql/updates/mysql/2.0.5.sql new file mode 100644 index 0000000..e5b4790 --- /dev/null +++ b/admin/sql/updates/mysql/2.0.5.sql @@ -0,0 +1,3 @@ +ALTER TABLE `#__membersmanager_type` ADD `edit_relationship` TEXT NOT NULL AFTER `description`; + +ALTER TABLE `#__membersmanager_type` ADD `view_relationship` TEXT NOT NULL AFTER `type`; diff --git a/admin/tables/member.php b/admin/tables/member.php index a14986e..9bc3cea 100644 --- a/admin/tables/member.php +++ b/admin/tables/member.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -220,7 +220,7 @@ class MembersmanagerTableMember extends JTable { // asset alread set so use saved rules $assetId = (int) $db->loadResult(); - return JAccess::getAssetRules($assetId); + return JAccess::getAssetRules($assetId); // (TODO) instead of keeping inherited Allowed it becomes Allowed. } // try again elseif ($try) diff --git a/admin/tables/type.php b/admin/tables/type.php index e7c2c1e..56aa636 100644 --- a/admin/tables/type.php +++ b/admin/tables/type.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -220,7 +220,7 @@ class MembersmanagerTableType extends JTable { // asset alread set so use saved rules $assetId = (int) $db->loadResult(); - return JAccess::getAssetRules($assetId); + return JAccess::getAssetRules($assetId); // (TODO) instead of keeping inherited Allowed it becomes Allowed. } // try again elseif ($try) diff --git a/admin/views/import/tmpl/default.php b/admin/views/import/tmpl/default.php index e9a7eb6..d9c260f 100644 --- a/admin/views/import/tmpl/default.php +++ b/admin/views/import/tmpl/default.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/import/view.html.php b/admin/views/import/view.html.php index 4a1f1d8..4b6e19f 100644 --- a/admin/views/import/view.html.php +++ b/admin/views/import/view.html.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/member/submitbutton.js b/admin/views/member/submitbutton.js index 31b8007..0e6cf69 100644 --- a/admin/views/member/submitbutton.js +++ b/admin/views/member/submitbutton.js @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/member/tmpl/edit.php b/admin/views/member/tmpl/edit.php index 4e12e32..42caacd 100644 --- a/admin/views/member/tmpl/edit.php +++ b/admin/views/member/tmpl/edit.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -306,11 +306,6 @@ jQuery('#adminForm').on('change', '#jform_account',function (e) jQuery('#error-profile-image-uploader').html(''); -jQuery(document).ready(function(){ - jQuery(window).load(function () { - jQuery("body").css('background', 'transparent'); - }); -}); jQuery('#adminForm').on('change', '#jform_token',function (e) { e.preventDefault(); var tokenValue = jQuery('#jform_token').val(); @@ -323,12 +318,6 @@ jQuery('#adminForm').on('change', '#jform_user',function (e) { // check if this token value is used getUserDetails(userValue); }); -jQuery('#adminForm').on('change', '#contact_country',function (e) { - e.preventDefault(); - getRegion(); -}); -var select_a_region = ''; -var create_a_region = ''; * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -223,14 +223,14 @@ class MembersmanagerViewMember extends JViewLegacy if ($isAdmin || $uikit != 3) { // add JavaScripts - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/uikit' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/uikit' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); } // add JavaScripts - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/accordion' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/tooltip' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/lightbox' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/notify' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/upload' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/accordion' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/tooltip' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/lightbox' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/notify' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/upload' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); } // Use Uikit Version 3 elseif (3 == $this->uikitVersion && ($isAdmin || $uikit != 2)) diff --git a/admin/views/members/tmpl/default.php b/admin/views/members/tmpl/default.php index a4cf4ba..43353a1 100644 --- a/admin/views/members/tmpl/default.php +++ b/admin/views/members/tmpl/default.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/members/tmpl/default_batch_body.php b/admin/views/members/tmpl/default_batch_body.php index 6332cca..16f41a5 100644 --- a/admin/views/members/tmpl/default_batch_body.php +++ b/admin/views/members/tmpl/default_batch_body.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/members/tmpl/default_batch_footer.php b/admin/views/members/tmpl/default_batch_footer.php index 0c7a150..a7459a6 100644 --- a/admin/views/members/tmpl/default_batch_footer.php +++ b/admin/views/members/tmpl/default_batch_footer.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/members/tmpl/default_body.php b/admin/views/members/tmpl/default_body.php index a30dfd7..6f39940 100644 --- a/admin/views/members/tmpl/default_body.php +++ b/admin/views/members/tmpl/default_body.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -88,11 +88,7 @@ $edit = "index.php?option=com_membersmanager&view=members&task=member.edit";
    - user->authorise('type.edit', 'com_membersmanager.type.' . (int)$item->type)): ?> - escape($item->type_name); ?> - - escape($item->type_name); ?> - : + escape($item->type); ?>: account); ?>
    escape($item->token); ?> diff --git a/admin/views/members/tmpl/default_foot.php b/admin/views/members/tmpl/default_foot.php index 0a533c0..a34998a 100644 --- a/admin/views/members/tmpl/default_foot.php +++ b/admin/views/members/tmpl/default_foot.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/members/tmpl/default_head.php b/admin/views/members/tmpl/default_head.php index 824acd9..e02a54c 100644 --- a/admin/views/members/tmpl/default_head.php +++ b/admin/views/members/tmpl/default_head.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/members/tmpl/default_toolbar.php b/admin/views/members/tmpl/default_toolbar.php index 5da5987..77c3fd5 100644 --- a/admin/views/members/tmpl/default_toolbar.php +++ b/admin/views/members/tmpl/default_toolbar.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/members/view.html.php b/admin/views/members/view.html.php index 819378c..4a40494 100644 --- a/admin/views/members/view.html.php +++ b/admin/views/members/view.html.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -37,6 +37,8 @@ class MembersmanagerViewMembers extends JViewLegacy $this->listOrder = $this->escape($this->state->get('list.ordering')); $this->listDirn = $this->escape($this->state->get('list.direction')); $this->saveOrder = $this->listOrder == 'ordering'; + // set the return here value + $this->return_here = urlencode(base64_encode((string) JUri::getInstance())); // get global action permissions $this->canDo = MembersmanagerHelper::getActions('member'); $this->canEdit = $this->canDo->get('member.edit'); @@ -226,28 +228,6 @@ class MembersmanagerViewMembers extends JViewLegacy JHtml::_('select.options', $this->main_memberUserOptions, 'value', 'text') ); } - } - - // Set Type Name Selection - $this->typeNameOptions = JFormHelper::loadFieldType('Types')->options; - if ($this->typeNameOptions) - { - // Type Name Filter - JHtmlSidebar::addFilter( - '- Select '.JText::_('COM_MEMBERSMANAGER_MEMBER_TYPE_LABEL').' -', - 'filter_type', - JHtml::_('select.options', $this->typeNameOptions, 'value', 'text', $this->state->get('filter.type')) - ); - - if ($this->canBatch && $this->canCreate && $this->canEdit) - { - // Type Name Batch Selection - JHtmlBatch_::addListSelection( - '- Keep Original '.JText::_('COM_MEMBERSMANAGER_MEMBER_TYPE_LABEL').' -', - 'batch[type]', - JHtml::_('select.options', $this->typeNameOptions, 'value', 'text') - ); - } } } diff --git a/admin/views/type/submitbutton.js b/admin/views/type/submitbutton.js index 79b56b9..63a42d6 100644 --- a/admin/views/type/submitbutton.js +++ b/admin/views/type/submitbutton.js @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/type/tmpl/edit.php b/admin/views/type/tmpl/edit.php index 4578833..e8337f9 100644 --- a/admin/views/type/tmpl/edit.php +++ b/admin/views/type/tmpl/edit.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -65,6 +65,17 @@ $componentParams = $this->params; // will be removed just use $this->params inst
    + +
    +
    + +
    +
    + +
    +
    + + ignore_fieldsets = array('details','metadata','vdmmetadata','accesscontrol'); ?> tab_name = 'typeTab'; ?> @@ -110,4 +121,23 @@ $componentParams = $this->params; // will be removed just use $this->params inst
    - + + + diff --git a/admin/views/type/view.html.php b/admin/views/type/view.html.php index 37a16a6..2a29062 100644 --- a/admin/views/type/view.html.php +++ b/admin/views/type/view.html.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/types/tmpl/default.php b/admin/views/types/tmpl/default.php index 5c52eea..3d644a7 100644 --- a/admin/views/types/tmpl/default.php +++ b/admin/views/types/tmpl/default.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/types/tmpl/default_batch_body.php b/admin/views/types/tmpl/default_batch_body.php index 77b766e..f0e6e8b 100644 --- a/admin/views/types/tmpl/default_batch_body.php +++ b/admin/views/types/tmpl/default_batch_body.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/types/tmpl/default_batch_footer.php b/admin/views/types/tmpl/default_batch_footer.php index e78db42..31967c5 100644 --- a/admin/views/types/tmpl/default_batch_footer.php +++ b/admin/views/types/tmpl/default_batch_footer.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/types/tmpl/default_body.php b/admin/views/types/tmpl/default_body.php index 946042f..e8dad55 100644 --- a/admin/views/types/tmpl/default_body.php +++ b/admin/views/types/tmpl/default_body.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -81,6 +81,9 @@ $edit = "index.php?option=com_membersmanager&view=types&task=type.edit"; escape($item->groups_access); ?> + + add_relationship); ?> + get('type.edit.state')) : ?> checked_out) : ?> diff --git a/admin/views/types/tmpl/default_foot.php b/admin/views/types/tmpl/default_foot.php index 64b8d57..a71c163 100644 --- a/admin/views/types/tmpl/default_foot.php +++ b/admin/views/types/tmpl/default_foot.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -14,5 +14,5 @@ defined('_JEXEC') or die('Restricted access'); ?> - pagination->getListFooter(); ?> + pagination->getListFooter(); ?> \ No newline at end of file diff --git a/admin/views/types/tmpl/default_head.php b/admin/views/types/tmpl/default_head.php index 5dd11da..c40e3dd 100644 --- a/admin/views/types/tmpl/default_head.php +++ b/admin/views/types/tmpl/default_head.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -41,6 +41,9 @@ defined('_JEXEC') or die('Restricted access'); + + + canState): ?> listDirn, $this->listOrder); ?> diff --git a/admin/views/types/tmpl/default_toolbar.php b/admin/views/types/tmpl/default_toolbar.php index 7adbd82..20a8f10 100644 --- a/admin/views/types/tmpl/default_toolbar.php +++ b/admin/views/types/tmpl/default_toolbar.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/admin/views/types/view.html.php b/admin/views/types/view.html.php index 6e647c6..31f79a0 100644 --- a/admin/views/types/view.html.php +++ b/admin/views/types/view.html.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -37,6 +37,8 @@ class MembersmanagerViewTypes extends JViewLegacy $this->listOrder = $this->escape($this->state->get('list.ordering')); $this->listDirn = $this->escape($this->state->get('list.direction')); $this->saveOrder = $this->listOrder == 'ordering'; + // set the return here value + $this->return_here = urlencode(base64_encode((string) JUri::getInstance())); // get global action permissions $this->canDo = MembersmanagerHelper::getActions('type'); $this->canEdit = $this->canDo->get('type.edit'); @@ -182,6 +184,28 @@ class MembersmanagerViewTypes extends JViewLegacy 'batch[access]', JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text') ); + } + + // Set Add Relationship Selection + $this->add_relationshipOptions = $this->getTheAdd_relationshipSelections(); + if ($this->add_relationshipOptions) + { + // Add Relationship Filter + JHtmlSidebar::addFilter( + '- Select '.JText::_('COM_MEMBERSMANAGER_TYPE_ADD_RELATIONSHIP_LABEL').' -', + 'filter_add_relationship', + JHtml::_('select.options', $this->add_relationshipOptions, 'value', 'text', $this->state->get('filter.add_relationship')) + ); + + if ($this->canBatch && $this->canCreate && $this->canEdit) + { + // Add Relationship Batch Selection + JHtmlBatch_::addListSelection( + '- Keep Original '.JText::_('COM_MEMBERSMANAGER_TYPE_ADD_RELATIONSHIP_LABEL').' -', + 'batch[add_relationship]', + JHtml::_('select.options', $this->add_relationshipOptions, 'value', 'text') + ); + } } } @@ -231,5 +255,41 @@ class MembersmanagerViewTypes extends JViewLegacy 'a.name' => JText::_('COM_MEMBERSMANAGER_TYPE_NAME_LABEL'), 'a.id' => JText::_('JGRID_HEADING_ID') ); + } + + protected function getTheAdd_relationshipSelections() + { + // Get a db connection. + $db = JFactory::getDbo(); + + // Create a new query object. + $query = $db->getQuery(true); + + // Select the text. + $query->select($db->quoteName('add_relationship')); + $query->from($db->quoteName('#__membersmanager_type')); + $query->order($db->quoteName('add_relationship') . ' ASC'); + + // Reset the query using our newly populated query object. + $db->setQuery($query); + + $results = $db->loadColumn(); + + if ($results) + { + // get model + $model = $this->getModel(); + $results = array_unique($results); + $_filter = array(); + foreach ($results as $add_relationship) + { + // Translate the add_relationship selection + $text = $model->selectionTranslation($add_relationship,'add_relationship'); + // Now add the add_relationship and its text to the options array + $_filter[] = JHtml::_('select.option', $add_relationship, JText::_($text)); + } + return $_filter; + } + return false; } } diff --git a/media/css/A4.print.css b/media/css/A4.print.css index bf59d62..9c7a6e2 100644 --- a/media/css/A4.print.css +++ b/media/css/A4.print.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/membersmanager.xml b/membersmanager.xml index 5d5c218..4e58325 100644 --- a/membersmanager.xml +++ b/membersmanager.xml @@ -1,20 +1,20 @@ COM_MEMBERSMANAGER - 26th September, 2018 + 27th December, 2018 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com https://www.joomlacomponentbuilder.com/ Copyright (C) 2015. All Rights Reserved GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html - 2.0.1 + 2.0.6 Members Manager (v.2.0.1) +

    Members Manager (v.2.0.6)

    A [Members manager](https://github.com/vdm-io/Joomla-Members-Manager) to use as a base for any kind of project that needs user integration. You can with much ease adapt it using the [JCB package](https://github.com/vdm-io/JCB-Community-Packages/raw/master/JCB_membersManager.zip). Watch this [tutorial](https://youtu.be/lkE0ZiSWufg) to see how.

    -

    Created by Llewellyn van der Merwe
    Development started 6th September, 2015

    +

    Created by Llewellyn van der Merwe
    Development started 6th July, 2018

    ]]>
    diff --git a/membersmanager_server.xml b/membersmanager_server.xml index f4b87de..4e25eac 100644 --- a/membersmanager_server.xml +++ b/membersmanager_server.xml @@ -152,4 +152,89 @@ https://www.joomlacomponentbuilder.com/ + + Members Manager + Members Manager + com_membersmanager + component + 2.0.2 + https://www.joomlacomponentbuilder.com/ + + https://github.com/vdm-io/Joomla-Members-Manager/releases/download/v2.0.6/JMM_v2.0.6.zip + + + stable + + Llewellyn van der Merwe + https://www.joomlacomponentbuilder.com/ + + + + Members Manager + Members Manager + com_membersmanager + component + 2.0.3 + https://www.joomlacomponentbuilder.com/ + + https://github.com/vdm-io/Joomla-Members-Manager/releases/download/v2.0.6/JMM_v2.0.6.zip + + + stable + + Llewellyn van der Merwe + https://www.joomlacomponentbuilder.com/ + + + + Members Manager + Members Manager + com_membersmanager + component + 2.0.4 + https://www.joomlacomponentbuilder.com/ + + https://github.com/vdm-io/Joomla-Members-Manager/releases/download/v2.0.6/JMM_v2.0.6.zip + + + stable + + Llewellyn van der Merwe + https://www.joomlacomponentbuilder.com/ + + + + Members Manager + Members Manager + com_membersmanager + component + 2.0.5 + https://www.joomlacomponentbuilder.com/ + + https://github.com/vdm-io/Joomla-Members-Manager/releases/download/v2.0.6/JMM_v2.0.6.zip + + + stable + + Llewellyn van der Merwe + https://www.joomlacomponentbuilder.com/ + + + + Members Manager + Members Manager + com_membersmanager + component + 2.0.6 + https://www.joomlacomponentbuilder.com/ + + https://github.com/vdm-io/Joomla-Members-Manager/releases/download/v2.0.6/JMM_v2.0.6.zip + + + stable + + Llewellyn van der Merwe + https://www.joomlacomponentbuilder.com/ + + \ No newline at end of file diff --git a/script.php b/script.php index ded601f..eaaddb8 100644 --- a/script.php +++ b/script.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -42,6 +42,168 @@ class com_membersmanagerInstallerScript // Get The Database object $db = JFactory::getDbo(); + // Create a new query object. + $query = $db->getQuery(true); + // Select ids from fields + $query->select($db->quoteName('id')); + $query->from($db->quoteName('#__fields')); + // Where member context is found + $query->where( $db->quoteName('context') . ' = '. $db->quote('com_membersmanager.member') ); + $db->setQuery($query); + // Execute query to see if context is found + $db->execute(); + $member_found = $db->getNumRows(); + // Now check if there were any rows + if ($member_found) + { + // Since there are load the needed member field ids + $member_field_ids = $db->loadColumn(); + // Remove member from the field table + $member_condition = array( $db->quoteName('context') . ' = '. $db->quote('com_membersmanager.member') ); + // Create a new query object. + $query = $db->getQuery(true); + $query->delete($db->quoteName('#__fields')); + $query->where($member_condition); + $db->setQuery($query); + // Execute the query to remove member items + $member_done = $db->execute(); + if ($member_done) + { + // If succesfully remove member add queued success message. + $app->enqueueMessage(JText::_('The fields with type (com_membersmanager.member) context was removed from the #__fields table')); + } + // Also Remove member field values + $member_condition = array( $db->quoteName('field_id') . ' IN ('. implode(',', $member_field_ids) .')'); + // Create a new query object. + $query = $db->getQuery(true); + $query->delete($db->quoteName('#__fields_values')); + $query->where($member_condition); + $db->setQuery($query); + // Execute the query to remove member field values + $member_done = $db->execute(); + if ($member_done) + { + // If succesfully remove member add queued success message. + $app->enqueueMessage(JText::_('The fields values for member was removed from the #__fields_values table')); + } + } + + // Create a new query object. + $query = $db->getQuery(true); + // Select ids from field groups + $query->select($db->quoteName('id')); + $query->from($db->quoteName('#__fields_groups')); + // Where member context is found + $query->where( $db->quoteName('context') . ' = '. $db->quote('com_membersmanager.member') ); + $db->setQuery($query); + // Execute query to see if context is found + $db->execute(); + $member_found = $db->getNumRows(); + // Now check if there were any rows + if ($member_found) + { + // Remove member from the field groups table + $member_condition = array( $db->quoteName('context') . ' = '. $db->quote('com_membersmanager.member') ); + // Create a new query object. + $query = $db->getQuery(true); + $query->delete($db->quoteName('#__fields_groups')); + $query->where($member_condition); + $db->setQuery($query); + // Execute the query to remove member items + $member_done = $db->execute(); + if ($member_done) + { + // If succesfully remove member add queued success message. + $app->enqueueMessage(JText::_('The field groups with type (com_membersmanager.member) context was removed from the #__fields_groups table')); + } + } + + // Create a new query object. + $query = $db->getQuery(true); + // Select id from content type table + $query->select($db->quoteName('type_id')); + $query->from($db->quoteName('#__content_types')); + // Where member alias is found + $query->where( $db->quoteName('type_alias') . ' = '. $db->quote('com_membersmanager.member') ); + $db->setQuery($query); + // Execute query to see if alias is found + $db->execute(); + $member_found = $db->getNumRows(); + // Now check if there were any rows + if ($member_found) + { + // Since there are load the needed member type ids + $member_ids = $db->loadColumn(); + // Remove member from the content type table + $member_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_membersmanager.member') ); + // Create a new query object. + $query = $db->getQuery(true); + $query->delete($db->quoteName('#__content_types')); + $query->where($member_condition); + $db->setQuery($query); + // Execute the query to remove member items + $member_done = $db->execute(); + if ($member_done) + { + // If succesfully remove member add queued success message. + $app->enqueueMessage(JText::_('The (com_membersmanager.member) type alias was removed from the #__content_type table')); + } + + // Remove member items from the contentitem tag map table + $member_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_membersmanager.member') ); + // Create a new query object. + $query = $db->getQuery(true); + $query->delete($db->quoteName('#__contentitem_tag_map')); + $query->where($member_condition); + $db->setQuery($query); + // Execute the query to remove member items + $member_done = $db->execute(); + if ($member_done) + { + // If succesfully remove member add queued success message. + $app->enqueueMessage(JText::_('The (com_membersmanager.member) type alias was removed from the #__contentitem_tag_map table')); + } + + // Remove member items from the ucm content table + $member_condition = array( $db->quoteName('core_type_alias') . ' = ' . $db->quote('com_membersmanager.member') ); + // Create a new query object. + $query = $db->getQuery(true); + $query->delete($db->quoteName('#__ucm_content')); + $query->where($member_condition); + $db->setQuery($query); + // Execute the query to remove member items + $member_done = $db->execute(); + if ($member_done) + { + // If succesfully remove member add queued success message. + $app->enqueueMessage(JText::_('The (com_membersmanager.member) type alias was removed from the #__ucm_content table')); + } + + // Make sure that all the member items are cleared from DB + foreach ($member_ids as $member_id) + { + // Remove member items from the ucm base table + $member_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $member_id); + // Create a new query object. + $query = $db->getQuery(true); + $query->delete($db->quoteName('#__ucm_base')); + $query->where($member_condition); + $db->setQuery($query); + // Execute the query to remove member items + $db->execute(); + + // Remove member items from the ucm history table + $member_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $member_id); + // Create a new query object. + $query = $db->getQuery(true); + $query->delete($db->quoteName('#__ucm_history')); + $query->where($member_condition); + $db->setQuery($query); + // Execute the query to remove member items + $db->execute(); + } + } + // Create a new query object. $query = $db->getQuery(true); // Select id from content type table @@ -305,7 +467,7 @@ class com_membersmanagerInstallerScript $member->table = '{"special": {"dbtable": "#__membersmanager_member","key": "id","type": "Member","prefix": "membersmanagerTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}'; $member->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "null","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","email":"email","account":"account","user":"user","token":"token","profile_image":"profile_image","not_required":"not_required","main_member":"main_member","password_check":"password_check","password":"password","useremail":"useremail","username":"username","surname":"surname","type":"type"}}'; $member->router = 'MembersmanagerHelperRoute::getMemberRoute'; - $member->content_history_options = '{"formFile": "administrator/components/com_membersmanager/models/forms/member.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","profile_image","not_required"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","account","user","main_member","type"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "user","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "main_member","targetTable": "#__membersmanager_member","targetColumn": "id","displayColumn": "user"},{"sourceColumn": "type","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"}]}'; + $member->content_history_options = '{"formFile": "administrator/components/com_membersmanager/models/forms/member.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","profile_image","not_required"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","account","user","main_member"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "user","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "main_member","targetTable": "#__membersmanager_member","targetColumn": "id","displayColumn": "user"},{"sourceColumn": "type","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"}]}'; // Set the object into the content types table. $member_Inserted = $db->insertObject('#__content_types', $member); @@ -315,9 +477,9 @@ class com_membersmanagerInstallerScript $type->type_title = 'Membersmanager Type'; $type->type_alias = 'com_membersmanager.type'; $type->table = '{"special": {"dbtable": "#__membersmanager_type","key": "id","type": "Type","prefix": "membersmanagerTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}'; - $type->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "alias","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","description":"description","groups_target":"groups_target","groups_access":"groups_access","alias":"alias"}}'; + $type->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "alias","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","description":"description","groups_target":"groups_target","groups_access":"groups_access","add_relationship":"add_relationship","field_type":"field_type","communicate":"communicate","view_relationship":"view_relationship","edit_relationship":"edit_relationship","type":"type","alias":"alias"}}'; $type->router = 'MembersmanagerHelperRoute::getTypeRoute'; - $type->content_history_options = '{"formFile": "administrator/components/com_membersmanager/models/forms/type.xml","hideFields": ["asset_id","checked_out","checked_out_time","version"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}]}'; + $type->content_history_options = '{"formFile": "administrator/components/com_membersmanager/models/forms/type.xml","hideFields": ["asset_id","checked_out","checked_out_time","version"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","add_relationship","field_type","communicate"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "view_relationship","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "edit_relationship","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "type","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"}]}'; // Set the object into the content types table. $type_Inserted = $db->insertObject('#__content_types', $type); @@ -327,7 +489,7 @@ class com_membersmanagerInstallerScript $query = $db->getQuery(true); // Field to update. $fields = array( - $db->quoteName('rules') . ' = ' . $db->quote('{"site.cpanel.access":{"1":1}}'), + $db->quoteName('rules') . ' = ' . $db->quote('{"site.members.access":{"1":1}}'), ); // Condition. $conditions = array( @@ -341,7 +503,7 @@ class com_membersmanagerInstallerScript $query = $db->getQuery(true); // Field to update. $fields = array( - $db->quoteName('params') . ' = ' . $db->quote('{"autorName":"Llewellyn van der Merwe","autorEmail":"llewellyn@joomlacomponentbuilder.com","crop_profile":"1","profile_height":"300","profile_width":"200","dynamic_salt":"1->!,3->E,4->A,6->b,9->d","country":"Namibia","check_in":"-1 day","save_history":"1","history_limit":"10","uikit_version":"2","uikit_load":"1","uikit_min":"","uikit_style":""}'), + $db->quoteName('params') . ' = ' . $db->quote('{"autorName":"Llewellyn van der Merwe","autorEmail":"llewellyn@joomlacomponentbuilder.com","placeholder_prefix":"member","members_display_type":"1","many_components":"0","crop_profile":"1","profile_height":"300","profile_width":"200","dynamic_salt":"1->!,3->E,4->A,6->b,9->d","country":"Namibia","check_in":"-1 day","save_history":"1","history_limit":"10","uikit_version":"2","uikit_load":"1","uikit_min":"","uikit_style":""}'), ); // Condition. $conditions = array( @@ -369,7 +531,7 @@ class com_membersmanagerInstallerScript $member->table = '{"special": {"dbtable": "#__membersmanager_member","key": "id","type": "Member","prefix": "membersmanagerTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}'; $member->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "null","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","email":"email","account":"account","user":"user","token":"token","profile_image":"profile_image","not_required":"not_required","main_member":"main_member","password_check":"password_check","password":"password","useremail":"useremail","username":"username","surname":"surname","type":"type"}}'; $member->router = 'MembersmanagerHelperRoute::getMemberRoute'; - $member->content_history_options = '{"formFile": "administrator/components/com_membersmanager/models/forms/member.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","profile_image","not_required"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","account","user","main_member","type"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "user","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "main_member","targetTable": "#__membersmanager_member","targetColumn": "id","displayColumn": "user"},{"sourceColumn": "type","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"}]}'; + $member->content_history_options = '{"formFile": "administrator/components/com_membersmanager/models/forms/member.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","profile_image","not_required"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","account","user","main_member"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "user","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "main_member","targetTable": "#__membersmanager_member","targetColumn": "id","displayColumn": "user"},{"sourceColumn": "type","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"}]}'; // Check if member type is already in content_type DB. $member_id = null; @@ -396,9 +558,9 @@ class com_membersmanagerInstallerScript $type->type_title = 'Membersmanager Type'; $type->type_alias = 'com_membersmanager.type'; $type->table = '{"special": {"dbtable": "#__membersmanager_type","key": "id","type": "Type","prefix": "membersmanagerTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}'; - $type->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "alias","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","description":"description","groups_target":"groups_target","groups_access":"groups_access","alias":"alias"}}'; + $type->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "alias","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","description":"description","groups_target":"groups_target","groups_access":"groups_access","add_relationship":"add_relationship","field_type":"field_type","communicate":"communicate","view_relationship":"view_relationship","edit_relationship":"edit_relationship","type":"type","alias":"alias"}}'; $type->router = 'MembersmanagerHelperRoute::getTypeRoute'; - $type->content_history_options = '{"formFile": "administrator/components/com_membersmanager/models/forms/type.xml","hideFields": ["asset_id","checked_out","checked_out_time","version"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}]}'; + $type->content_history_options = '{"formFile": "administrator/components/com_membersmanager/models/forms/type.xml","hideFields": ["asset_id","checked_out","checked_out_time","version"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","add_relationship","field_type","communicate"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "view_relationship","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "edit_relationship","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "type","targetTable": "#__membersmanager_type","targetColumn": "id","displayColumn": "name"}]}'; // Check if type type is already in content_type DB. $type_id = null; @@ -424,7 +586,7 @@ class com_membersmanagerInstallerScript echo ' -

    Upgrade to Version 2.0.1 Was Successful! Let us know if anything is not working as expected.

    '; +

    Upgrade to Version 2.0.6 Was Successful! Let us know if anything is not working as expected.

    '; } } } diff --git a/site/assets/css/cpanel.css b/site/assets/css/cpanel.css index 026520f..3a84864 100644 --- a/site/assets/css/cpanel.css +++ b/site/assets/css/cpanel.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/assets/css/member.css b/site/assets/css/member.css index 58d7189..095d0de 100644 --- a/site/assets/css/member.css +++ b/site/assets/css/member.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/assets/css/members.css b/site/assets/css/members.css new file mode 100644 index 0000000..3a84864 --- /dev/null +++ b/site/assets/css/members.css @@ -0,0 +1,13 @@ +/** + * @package Joomla.Members.Manager + * + * @created 6th July, 2018 + * @author Llewellyn van der Merwe + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +/* CSS Document */ + + diff --git a/site/assets/css/profile.css b/site/assets/css/profile.css index 026520f..3a84864 100644 --- a/site/assets/css/profile.css +++ b/site/assets/css/profile.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/assets/css/site.css b/site/assets/css/site.css index 7a19d60..f293af0 100644 --- a/site/assets/css/site.css +++ b/site/assets/css/site.css @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/assets/js/cpanel.js b/site/assets/js/cpanel.js index e365442..1e27599 100644 --- a/site/assets/js/cpanel.js +++ b/site/assets/js/cpanel.js @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/assets/js/profile.js b/site/assets/js/profile.js index 3d4cff9..2032c92 100644 --- a/site/assets/js/profile.js +++ b/site/assets/js/profile.js @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -58,4 +58,19 @@ function setReport(data) { jQuery('.setreport').html(data); // hide spinner jQuery('.report-spinner').hide(); -} \ No newline at end of file +} +// load chart in modal +function loadTheChartInModal(callback, targetDivID){ + // remove old data and add spinner + jQuery('.setreport').html(''); + jQuery('.report-spinner').show(); + // add new div + jQuery('.setreport').html('Print
    '); + // allow modal to open + setTimeout(function() { + // hide spinner + jQuery('.report-spinner').hide(); + // run call back + callback(); + }, 800); +} \ No newline at end of file diff --git a/site/assets/js/site.js b/site/assets/js/site.js index f6daf95..16c13ac 100644 --- a/site/assets/js/site.js +++ b/site/assets/js/site.js @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/controller.php b/site/controller.php index 9759f9e..3525ae9 100644 --- a/site/controller.php +++ b/site/controller.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -29,7 +29,7 @@ class MembersmanagerController extends JControllerLegacy function display($cachable = false, $urlparams = false) { // set default view if not set - $view = $this->input->getCmd('view', 'cpanel'); + $view = $this->input->getCmd('view', 'members'); $this->input->set('view', $view); $isEdit = $this->checkEditView($view); $layout = $this->input->get('layout', null, 'WORD'); @@ -68,7 +68,7 @@ class MembersmanagerController extends JControllerLegacy else { // normal redirect back to the list default site view - $this->setRedirect(JRoute::_('index.php?option=com_membersmanager&view=cpanel', false)); + $this->setRedirect(JRoute::_('index.php?option=com_membersmanager&view=members', false)); } return false; } diff --git a/site/controllers/ajax.json.php b/site/controllers/ajax.json.php index 5e92ef9..dbfdad3 100644 --- a/site/controllers/ajax.json.php +++ b/site/controllers/ajax.json.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -27,9 +27,11 @@ class MembersmanagerControllerAjax extends JControllerLegacy // load the tasks $this->registerTask('checkUnique', 'ajax'); $this->registerTask('getPlaceHolders', 'ajax'); + $this->registerTask('getAnyPlaceHolders', 'ajax'); $this->registerTask('uploadfile', 'ajax'); $this->registerTask('removeFile', 'ajax'); $this->registerTask('getUserDetails', 'ajax'); + $this->registerTask('getChartImageLink', 'ajax'); $this->registerTask('searchMembers', 'ajax'); $this->registerTask('getReport', 'ajax'); } @@ -123,6 +125,44 @@ class MembersmanagerControllerAjax extends JControllerLegacy } } break; + case 'getAnyPlaceHolders': + try + { + $returnRaw = $jinput->get('raw', false, 'BOOLEAN'); + $getTypeValue = $jinput->get('getType', NULL, 'WORD'); + if($getTypeValue && $user->id != 0) + { + $result = $this->getModel('ajax')->getAnyPlaceHolders($getTypeValue); + } + else + { + $result = false; + } + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback . "(".json_encode($result).");"; + } + elseif($returnRaw) + { + echo json_encode($result); + } + else + { + echo "(".json_encode($result).");"; + } + } + catch(Exception $e) + { + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback."(".json_encode($e).");"; + } + else + { + echo "(".json_encode($e).");"; + } + } + break; case 'uploadfile': try { @@ -241,6 +281,44 @@ class MembersmanagerControllerAjax extends JControllerLegacy } } break; + case 'getChartImageLink': + try + { + $returnRaw = $jinput->get('raw', false, 'BOOLEAN'); + $imageValue = $jinput->get('image', NULL, 'STRING'); + if($imageValue && $user->id != 0) + { + $result = $this->getModel('ajax')->getChartImageLink($imageValue); + } + else + { + $result = false; + } + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback . "(".json_encode($result).");"; + } + elseif($returnRaw) + { + echo json_encode($result); + } + else + { + echo "(".json_encode($result).");"; + } + } + catch(Exception $e) + { + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback."(".json_encode($e).");"; + } + else + { + echo "(".json_encode($e).");"; + } + } + break; case 'searchMembers': try { diff --git a/site/controllers/member.php b/site/controllers/member.php index 63ce8a6..bb5d6b2 100644 --- a/site/controllers/member.php +++ b/site/controllers/member.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -35,7 +35,7 @@ class MembersmanagerControllerMember extends JControllerForm */ public function __construct($config = array()) { - $this->view_list = 'cpanel'; // safeguard for setting the return view listing to the default site view. + $this->view_list = 'members'; // safeguard for setting the return view listing to the default site view. parent::__construct($config); } @@ -316,7 +316,17 @@ class MembersmanagerControllerMember extends JControllerForm protected function postSaveHook(JModelLegacy $model, $validData = array()) { // safe all dynamic values (that has been posted) - MembersmanagerHelper::saveDynamicValues($validData, 'member'); + if (isset($validData['id'])) + { + MembersmanagerHelper::saveDynamicValues($validData, 'member'); + // always sync the type with the type_map + if (isset($validData['type'])) + { + MembersmanagerHelper::updateTypes($validData['id'], $validData['type']); + } + // safe all set relationships + MembersmanagerHelper::saveRelationships($validData); + } return; } diff --git a/site/helpers/category.php b/site/helpers/category.php index 2dcbbf1..c3f7bd4 100644 --- a/site/helpers/category.php +++ b/site/helpers/category.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/helpers/headercheck.php b/site/helpers/headercheck.php index 4c1d712..b380a0d 100644 --- a/site/helpers/headercheck.php +++ b/site/helpers/headercheck.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/helpers/membersmanager.php b/site/helpers/membersmanager.php index 71076c2..9e41834 100644 --- a/site/helpers/membersmanager.php +++ b/site/helpers/membersmanager.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -33,57 +33,19 @@ abstract class MembersmanagerHelper protected static $params; /** - * Get placeholders - * - * @param string $type The type of placeholders to return - * - * @return array - * - */ - public static function getPlaceHolders($type) - { - if ('document' === $type) - { - // get company placeholders - if (($company = self::getCompanyDetails('placeholder')) !== false && self::checkArray($company)) - { - // just remove the footer and header placeholders - unset($company['[company_doc_header]']); - unset($company['[company_doc_footer]']); - $placeholders = array_keys($company); - return $placeholders; - } - } - return false; - } + * the button names + **/ + protected static $buttonNames = array(); /** - * Add Join Tables based on filter - * - * @param object $query The database query object - * @param string $filter The target area that made the request - * - * @return array - * - */ - protected static function joinMemberDetails(&$query, $filter = 'none', $db = null) - { - // check if we have the DB object - if (!self::checkObject($db)) - { - // get the database object - $db = JFactory::getDBO(); - } - if ('none' === $filter) - { - // From the users table. - $query->join('LEFT', $db->quoteName('#__users', 'u') . ' ON (' . $db->quoteName('a.user') . ' = ' . $db->quoteName('u.id') . ')'); - // From the membersmanager_member table. - $query->join('LEFT', $db->quoteName('#__membersmanager_member', 'm') . ' ON (' . $db->quoteName('a.main_member') . ' = ' . $db->quoteName('m.id') . ')'); - // From the membersmanager_type table. - $query->join('LEFT', $db->quoteName('#__membersmanager_type', 't') . ' ON (' . $db->quoteName('a.type') . ' = ' . $db->quoteName('t.id') . ')'); - } - } + * the opener + **/ + protected static $opener; + + /** + * the return here path + **/ + protected static $return_here; /** * Get selection based on type @@ -98,16 +60,47 @@ abstract class MembersmanagerHelper */ protected static function getSelection($table = 'member', $method = 'placeholder', $filter = 'none', $db = null) { + // get the global settings + if (!self::checkObject(self::$params)) + { + self::$params = JComponentHelper::getParams('com_membersmanager'); + } // prep for placeholders $f = ''; $b = ''; if ('placeholder' === $method) { - $f = '[member_'; + // get the placeholder prefix + $prefix = self::$params->get('placeholder_prefix', 'membersmanager'); + $f = '[' . $prefix . '_'; $b = ']'; } + // get charts + if ('chart' !== $filter && 'field' !== $filter && method_exists(__CLASS__, 'getAnyAvailableCharts') && method_exists(__CLASS__, 'getAllComponents')) + { + if (($components = self::getAllComponents(null, array('Assessment'))) !== false && self::checkArray($components)) + { + // Chart Target Types + $targets = array(2,3); + // load per component + foreach ($targets as $target) + { + foreach ($components as $component) + { + if (($data = self::getAnyAvailableCharts(null, $target, $component->element)) !== false && self::checkArray($data)) + { + $com = str_replace('com_', '', $component->element); + foreach ($data as $key => $chartData) + { + $charts[$key . '\^/' . $component->element . '\^/' . $target] = $com . '_' . $key; + } + } + } + } + } + } // only get what we need - if ('none' === $filter) + if ('email' === $filter || 'report' === $filter) { // check if we have the DB object if (!self::checkObject($db)) @@ -127,27 +120,505 @@ abstract class MembersmanagerHelper // prep the columns $columns = array_keys($columns); } - // convert the columns for query selection - $selection = array(); - foreach ($columns as $column) + // check if we have columns + if (isset($columns) && self::checkArray($columns)) { - $selection['a.' . $column] = $f . $column . $b; + // convert the columns for query selection + $selection = array(); + foreach ($columns as $column) + { + $selection['a.' . $column] = $f . $column . $b; + // we must add the params + if ('profile' !== $filter && 'field' !== $filter) + { + // set the label for these fields + $selection['setLabel->' . $column] = $f . 'label_' . $column . $b; + } + } + // needed values + if ('member' === $table) + { + // set names and emails + $selection['setMemberName:id|user|name|surname'] = $f . 'name' . $b; + $selection['setMemberEmail:id|user|email'] = $f . 'email' . $b; + $selection['setMemberName:created_by|user'] = $f . 'created_name' . $b; + $selection['setMemberEmail:created_by|user'] = $f . 'created_email' . $b; + $selection['setMemberName:modified_by|user'] = $f . 'modified_name' . $b; + $selection['setMemberEmail:modified_by|user'] = $f . 'modified_email' . $b; + // get name and email + $selection['getMemberName:main_member'] = $f . 'main_name' . $b; + $selection['getMemberEmail:main_member'] = $f . 'main_email' . $b; + // set fancy dates + $selection['fancyDate:created'] = $f . 'created' . $b; + $selection['fancyDate:modified'] = $f . 'modified' . $b; + // set profile image + $selection['setImageLink:profile_image|name'] = $f . 'profile_image_url' . $b; + $selection['setImageHTML:profile_image_url|name'] = $f . 'profile_image_html' . $b; + // set profile + $selection['setProfileLink:id|token'] = $f . 'profile_link_url' . $b; + // set the return value + self::$return_here = urlencode(base64_encode((string) JUri::getInstance())); + // set edit link + $selection['setMemberEditURL:id|created_by'] = $f . 'edit_url' . $b; + // Get the medium encryption. + $mediumkey = MembersmanagerHelper::getCryptKey('medium'); + if ($mediumkey) + { + // Get the encryption object. + self::$opener = new FOFEncryptAes($mediumkey); + } + } + // add the chart div and JS code (only if filter is not chart) + if ('chart' !== $filter && 'field' !== $filter && isset($charts) && self::checkArray($charts)) + { + foreach ($charts as $chart => $value) + { + // make sure the chart name is save + $selection['setMultiChart->' . $chart] = $f . $value . $b; + } + } + return $selection; } - // add joined values if needed (based on filter) - if ('member' === $table && 'none' === $filter) - { - $selection['u.name'] = $f . 'user_name' . $b; - $selection['u.email'] = $f . 'user_email' . $b; - $selection['t.name'] = $f . 'type_name' . $b; - $selection['m.user'] = $f . 'main_user' . $b; - $selection['m.name'] = $f . 'main_name' . $b; - $selection['m.email'] = $f . 'main_email' . $b; - } - return $selection; + return false; } /** - * Get a user Access Types + * set image HTML + **/ + protected static function setImageHTML($object) + { + return '' . $object->get('name', JText::_('COM_MEMBERSMANAGER_MEMBER')) . ' ' . JText::_('COM_MEMBERSMANAGER_IMAGE') . ''; + } + + /** + * set image link + **/ + protected static function setImageLink($item) + { + if (self::checkObject(self::$opener) && ($image = $item->get('profile_image', false)) !== false && !is_numeric($image) && $image === base64_encode(base64_decode($image, true))) + { + // now unlock + $item->set('profile_image', rtrim(self::$opener->decryptString($image), "\0")); + } + // get link + return self::getImageLink($item, 'profile_image', 'name', null, false); + } + + /** + * set member edit url + **/ + protected static function setMemberEditURL($item) + { + if (($url = self::getEditURL($item, 'member', 'members', '&return=' . self::$return_here)) !== false) + { + return $url; + } + return ''; + } + + /** + * set profile link + **/ + protected static function setProfileLink($object) + { + return JRoute::_('index.php?option=com_membersmanager&view=profile&id='. $object->get('id') . ':' . $object->get('token') . '&return=' . self::$return_here); + } + + /** + * set member name + **/ + protected static function setMemberName($object) + { + // check if this is a created by or modified by + if (($user = $object->get('created_by', false)) !== false || ($user = $object->get('modified_by', false)) !== false ) + { + $object->set('user', $user); + } + return self::getMemberName($object->get('id', null), $object->get('user', null), $object->get('name', null), $object->get('surname', null)); + } + + /** + * set member email + **/ + protected static function setMemberEmail($object) + { + // check if this is a created by or modified by + if (($user = $object->get('created_by', false)) !== false || ($user = $object->get('modified_by', false)) !== false ) + { + $object->set('user', $user); + } + return self::getMemberEmail($object->get('id', null), $object->get('user', null), $object->get('email', null)); + } + + /** + * set the session defaults if not set + **/ + protected static function setSessionDefaults() + { + // noting for now + return true; + } + + /** + * get button name + **/ + public static function getButtonName($type, $default) + { + if (!isset(self::$buttonNames[$type])) + { + // get the global settings + if (!self::checkObject(self::$params)) + { + self::$params = JComponentHelper::getParams('com_membersmanager'); + } + // get the button name + self::$buttonNames[$type] = self::$params->get('button_'. $type . '_name', $default); + } + return self::$buttonNames[$type]; + } + + /** + * check if the communication component is set (and get key value) + **/ + public static function communicate($key = null, $default = false, $return = null) + { + if (JComponentHelper::isInstalled('com_communicate') && JComponentHelper::isEnabled('com_communicate')) + { + // check if looking for create_url + if ($key && 'create_url' === $key) + { + $_return = urlencode(base64_encode((string) JUri::getInstance())); + if ($return) + { + return self::getCreateURL('message', 'message', $return . '&return=' . $_return, 'com_communicate'); + } + return self::getCreateURL('message', 'message', '&return=' . $_return, 'com_communicate'); + } + // get the global settings of com_communicate (singleton) + $params = JComponentHelper::getParams('com_communicate'); + // return the key value + if ($key) + { + return $params->get($key, $default); + } + return $params; + } + return $default; + } + + /** + * remove all groups that are part of target groups in the member types + **/ + public static function removeMemberGroups(&$groups) + { + if (self::checkArray($groups)) + { + // get database object + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + $query->select(array('a.id')); + $query->from('#__membersmanager_type AS a'); + $db->setQuery($query); + $db->execute(); + // get all types + $types = $db->loadColumn(); + // now get all target groups + $groups_target = self::getMemberGroupsByType($types, 'groups_target'); + // now update the groups + $groups = array_diff($groups, $groups_target); + } + } + + /** + * Get any placeholders + * + * @param string $component The component placeholders to return + * @param string $type The type of placeholders to return + * @param bool $addCompany The switch to add the company + * + * @return array + * + */ + public static function getAnyPlaceHolders($_component, $type = 'report', $addCompany = false) + { + // check if we are in the correct class + if ('com_membersmanager' !== $_component) + { + // check if the class and method exist + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getPlaceHolders')) + { + return $helperClass::getPlaceHolders($type, $addCompany); + } + } + // check if the class and method exist + elseif (method_exists(__CLASS__, 'getPlaceHolders')) + { + return self::getPlaceHolders($type, $addCompany, 'member'); + } + return false; + } + + + /** + * Get placeholders + * + * @param string $type The type of placeholders to return + * @param bool $addCompany The switch to add the company + * @param string $table The table being targeted + * + * @return array + * + */ + public static function getPlaceHolders($type = 'report', $addCompany = false, $table = 'form') + { + // start loading the placeholders + $placeholders = array(); + if (method_exists(__CLASS__, 'getSelection')) + { + // get form placeholders + if (('report' === $type || 'chart' === $type) && ($form = self::getSelection($table, 'placeholder', $type)) !== false && self::checkArray($form)) + { + // always remove params, since it should never be used in placeholders + unset($form['a.params']); + // be sure to sort the array + sort($form); + // and remove duplicates + $form = array_unique(array_values($form)); + // check if company should be added + if ($addCompany) + { + $placeholders[] = $form; + } + else + { + return $form; + } + } + } + // get company placeholders + if (('document' === $type || $addCompany) && method_exists(__CLASS__, 'getAnyCompanyDetails') && ($company = self::getAnyCompanyDetails('com_membersmanager', 'placeholder')) !== false && self::checkArray($company)) + { + if ('document' === $type) + { + // just remove the footer and header placeholders + unset($company['[company_doc_header]']); + unset($company['[company_doc_footer]']); + } + $placeholders[] = array_keys($company); + } + // check that we have placeholders + if (self::checkArray($placeholders)) + { + return self::mergeArrays($placeholders); + } + return false; + } + + + /** + * The Type Members Memory + * + * @var array + */ + protected static $typeMembers = array(); + + /** + * get members by type + * + * @param int/array $id The Type ID + * @param object $db Database object + * + * @return array of member IDs + * + */ + public static function getMembersByType(&$id, $db) + { + // if the id is an array + if (self::checkArray($id)) + { + $members = array(); + foreach ($id as $_id) + { + if (($_members = self::getMembersByType($_id, $db)) !== false) + { + $members[] = $_members; + } + } + return self::mergeArrays($members); + } + // check if we already have the members set by type + if (!self::checkArray(self::$typeMembers) || !isset(self::$typeMembers[$id]) || !self::checkArray(self::$typeMembers[$id])) + { + // check that we have the database object + if (!$db) + { + // get DB + $db = JFactory::getDBO(); + } + // get types that allow relationships + $query = $db->getQuery(true); + $query->select('a.member'); + $query->from('#__membersmanager_type_map AS a'); + $query->where('a.type = ' . (int) $id); + $query->where('a.member > 0'); + $db->setQuery($query); + $db->execute(); + // only continue if we have member types + if (($members = $db->loadColumn()) !== false && self::checkArray($members)) + { + self::$typeMembers[$id] = $members; + } + } + // check if we found member types + if (self::checkArray(self::$typeMembers) && isset(self::$typeMembers[$id]) && self::checkArray(self::$typeMembers[$id])) + { + return self::$typeMembers[$id]; + } + return false; + } + + + /** + * get the relationships by types + * + * @param object $member_types Member Types + * @param object $db Database object + * @param bool $filter_edit Switch to filter by edit relationship + * @param bool $filter_view Switch to filter by view relationship + * @param bool $load_members Switch to load the members of the types + * + * @return array + * + */ + public static function getRelationshipsByTypes(&$member_types, $db, $filter_edit = false, $filter_view = true, $load_members = true) + { + // little function to get types + $getTypes = function($type) { return (isset($type)) ? ((self::checkJson($type)) ? json_decode($type, true) : ((self::checkArray($type)) ? $type : false)) : false; }; + // get this member types + if (($member_types = $getTypes($member_types)) === false || (($user_types = $getTypes(self::getVar('member', JFactory::getUser()->id, 'user', 'type'))) === false || !self::checkArray($user_types) && ($filter_edit || $filter_view))) + { + return false; + } + // check that we have the database object + if (!$db) + { + // get DB + $db = JFactory::getDBO(); + } + // get types that allow relationships + $query = $db->getQuery(true); + $query->select(array('a.id', 'a.name', 'a.description', 'a.type', 'a.edit_relationship', 'a.view_relationship', 'a.field_type', 'a.communicate')); + $query->from('#__membersmanager_type AS a'); + $query->where($db->quoteName('a.published') . ' >= 1'); + $query->where($db->quoteName('a.add_relationship') . ' = 1'); + $db->setQuery($query); + $db->execute(); + // only continue if we have member types and all relationship types + if (($types = $db->loadObjectList('id')) !== false && self::checkArray($types)) + { + // our little function to check if two arrays intersect on values + $intersect = function ($a, $b) { $b = array_flip($b); foreach ($a as $v) { if (isset($b[$v])) return true; } return false; }; + // the bucket + $bucket = array(); + // get all types related to this member + foreach($types as $id => $value) + { + if (($value->type = $getTypes($value->type)) !== false && $intersect($member_types, $value->type) + && (($value->view_relationship = $getTypes($value->view_relationship)) !== false && $intersect($user_types, $value->view_relationship) || !$filter_view) + && (($value->edit_relationship = $getTypes($value->edit_relationship)) !== false && $intersect($user_types, $value->edit_relationship) || !$filter_edit)) + { + // set the type + $bucket[$id] = $value; + if ($load_members) + { + // now get all members that belong to this type + $bucket[$id]->members = self::getMembersByType($id, $db); + } + } + } + // return if we found any + if (self::checkArray($bucket)) + { + return $bucket; + } + } + return false; + } + + + /** + * get the relationships by member + * + * @param object $member Member ID + * @param object $db Database object + * @param string $direction The relationship direction + * + * @return array + * + */ + public static function getRelationshipsByMember(&$member, $db, $direction = 'member') + { + // always check that we have an ID + if (!is_numeric($member) || $member == 0) + { + return false; + } + // check that we have the database object + if (!$db) + { + // get DB + $db = JFactory::getDBO(); + } + // set the direction relationship + $_direction = 'relation'; + if ('relation' === $direction) + { + $_direction = 'member'; + } + // get types that allow relationships + $query = $db->getQuery(true); + $query->select(array('a.' . $_direction, 'a.type')); + $query->from('#__membersmanager_relation_map AS a'); + $query->where($db->quoteName('a.' . $direction) . ' = ' . (int) $member); + $db->setQuery($query); + $db->execute(); + // only continue if we have member relationships + if (($relationships = $db->loadObjectList()) !== false && self::checkArray($relationships)) + { + // the bucket + $bucket = array(); + // sort by types + foreach($relationships as $relationship) + { + if (!isset($bucket[$relationship->type])) + { + $bucket[$relationship->type] = array(); + } + // set the type + $bucket[$relationship->type][$relationship->{$_direction}] = $relationship->{$_direction}; + } + return $bucket; + } + return false; + } + + + /** + * The Access Memory + * + * @var array + */ + protected static $accessMemory = array(); + + /** + * The Key to Access Memory + * + * @var string + */ + protected static $acK3y; + + /** + * Get a user Access Types/Groups * * @param mix $id The the user ID/object * @param int $type The type of access to return (1 = type, 2 = groups) @@ -158,11 +629,6 @@ abstract class MembersmanagerHelper */ public static function getAccess($user = null, $type = 1, $db = null) { - // get DB - if (!$db) - { - $db = JFactory::getDBO(); - } // get user if (!self::checkObject($user)) { @@ -175,113 +641,51 @@ abstract class MembersmanagerHelper $user = JFactory::getUser(); } } - // function to setup the group array - $getGroups = function ($groups) { - // convert to array - if (self::checkJson($groups)) + // check memory first + self::$acK3y = md5($user->get('id', 'not_set') . '_' . $type); + if (isset(self::$accessMemory[self::$acK3y])) + { + return self::$accessMemory[self::$acK3y]; + } + // fallback to false + self::$accessMemory[self::$acK3y] = false; + // get DB + if (!$db) + { + $db = JFactory::getDBO(); + } + // get user Access groups + if (2 == $type) + { + self::$accessMemory[self::$acK3y] = self::getAccessGroups($user, $db); + } + elseif (1 == $type) + { + // return access types + self::$accessMemory[self::$acK3y] = self::getAccessTypes($user, $db); + } + return self::$accessMemory[self::$acK3y]; + } + + /** + * Get a user Access Groups + * + * @param object $user The user object + * @param object $db The database object + * + * @return mix array + * + */ + protected static function getAccessGroups(&$user, &$db) + { + // check if access is needed + if (!$user->authorise('core.options', 'com_membersmanager')) + { + if (($userID = $user->get('id', false)) !== false && $userID > 0 && ($types = self::getVar('member', $userID, 'user', 'type')) !== false) { - return (array) json_decode($groups, true); - } - elseif (is_numeric($groups)) - { - return array($groups); + return self::getMemberGroupsByType($types, 'groups_access'); } return false; - }; - // merge groups - $mergeGroups = function ($types) use($getGroups){ - $bucket = array(); - foreach ($types as $id => $groups) - { - $groups = $getGroups($groups); - if (self::checkArray($groups)) - { - foreach ($groups as $group) - { - $bucket[$group] = $group; - } - } - } - return $bucket; - }; - // check if access it needed - if (!$user->authorise('core.admin')) - { - // get all types - $query = $db->getQuery(true); - $query->select(array('a.id', 'a.groups_access')); - $query->from('#__membersmanager_type AS a'); - $db->setQuery($query); - $db->execute(); - // get all types - $types = $db->loadAssocList('id', 'groups_access'); - if (self::checkArray($types)) - { - $bucket = array(); - foreach ($types as $id => $groups_access) - { - $groups_access = $getGroups($groups_access); - if (self::checkArray($groups_access) && array_intersect($groups_access, $user->groups)) - { - $bucket[$id] = $id; - } - } - // return types that this member can access - if (1 == $type && self::checkArray($bucket)) - { - return $bucket; - } - elseif (self::checkArray($bucket)) - { - // get the targeted groups - $query = $db->getQuery(true); - $query->select(array('a.id', 'a.groups_target')); - $query->from('#__membersmanager_type AS a'); - $query->where('a.id IN ('. implode(',', $bucket) . ')'); - $db->setQuery($query); - $db->execute(); - // get all types - $targettypes = $db->loadAssocList('id', 'groups_target'); - if (self::checkArray($targettypes)) - { - $targetbucket = $mergeGroups($targettypes); - // return types that this member can access - if (self::checkArray($targetbucket)) - { - return $targetbucket; - } - } - } - } - return false; - } - // return all types/groups - $query = $db->getQuery(true); - if (1 == $type) - { - $query->select(array('a.id')); - } - else - { - $query->select(array('a.id', 'a.groups_target')); - } - $query->from('#__membersmanager_type AS a'); - $db->setQuery($query); - $db->execute(); - if (1 == $type) - { - return $db->loadColumn(); - } - // get all types with group target - $types = $db->loadAssocList('id', 'groups_target'); - if (self::checkArray($types)) - { - $bucket = $mergeGroups($types); - // return types that this member can access - if (self::checkArray($bucket)) - { - return $bucket; - } } // return all groups $query = $db->getQuery(true); @@ -293,13 +697,131 @@ abstract class MembersmanagerHelper } /** - * set the session defaults if not set - **/ - protected static function setSessionDefaults() + * Get a user Access Types + * + * @param object $user The user object + * @param object $db The database object + * + * @return mix array + * + */ + protected static function getAccessTypes(&$user, &$db) { - // noting for now - return true; + // check if access is needed + if (!$user->authorise('core.options', 'com_membersmanager')) + { + // get all types in system + $query = $db->getQuery(true); + $query->select(array('a.id', 'a.groups_target')); // groups_target = type_link + $query->from('#__membersmanager_type AS a'); + $query->where($db->quoteName('a.published') . ' >= 1'); + // also filter by access (will keep an eye on this) + $groups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $groups . ')'); + $db->setQuery($query); + $db->execute(); + // get all types + $types = $db->loadAssocList('id', 'groups_target'); + // make sure we have types, and user access groups + if (self::checkArray($types) && ($groups_access = self::getAccessGroups($user, $db)) !== false) + { + // function to setup the group array + $setGroups = function ($groups) { + // convert to array + if (self::checkJson($groups)) + { + return (array) json_decode($groups, true); + } + elseif (is_numeric($groups)) + { + return array($groups); + } + return false; + }; + // our little function to check if two arrays intersect on values + $intersect = function ($a, $b) { $b = array_flip($b); foreach ($a as $v) { if (isset($b[$v])) return true; } return false; }; + // type bucket + $bucketTypes = array(); + foreach ($types as $id => $groups_target) + { + $groups_target = $setGroups($groups_target); + if (self::checkArray($groups_target) && $intersect($groups_target, $groups_access)) + { + $bucketTypes[$id] = $id; + } + } + // check if we found any + if (self::checkArray($bucketTypes)) + { + return $bucketTypes; + } + } + return false; + } + // return all types + $query = $db->getQuery(true); + $query->select(array('a.id')); + $query->from('#__membersmanager_type AS a'); + $query->where($db->quoteName('a.published') . ' >= 1'); + $db->setQuery($query); + $db->execute(); + return $db->loadColumn(); } + + /** + * Get a user Access Types/Groups + * + * @param mix $types The member types + * @param string $groupType The type of groups + * + * @return mix array + * + */ + public static function getMemberGroupsByType($types, $groupType = 'groups_target') + { + // convert type json to array + if (self::checkJson($types)) + { + $types = json_decode($types, true); + } + // convert type int to array + if (is_numeric($types) && $types > 0) + { + $types = array($types); + } + // make sure we have an array + if (self::checkArray($types)) + { + $groups = array(); + foreach ($types as $type) + { + // get the target groups + $groups_target = self::getVar('type', $type, 'id', $groupType); + // convert to array + if (self::checkJson($groups_target)) + { + $groups_target = (array) json_decode($groups_target, true); + } + // convert type int to array + if (is_numeric($groups_target)) + { + $groups_target = array((int) $groups_target); + } + // make sure we have an array + if (self::checkArray($groups_target)) + { + $groups[] = $groups_target; + } + } + // make sure we have an array + if (self::checkArray($groups)) + { + return self::mergeArrays($groups); + } + } + return false; + } + /** * Change to nice fancy date @@ -349,6 +871,30 @@ abstract class MembersmanagerHelper return date('G:i',$time); } + /** + * set the date as 2004/05 (for charts) + */ + public static function setYearMonth($date) + { + if (!self::isValidTimeStamp($date)) + { + $date = strtotime($date); + } + return date('Y/m', $date); + } + + /** + * set the date as 2004/05/03 (for charts) + */ + public static function setYearMonthDay($date) + { + if (!self::isValidTimeStamp($date)) + { + $date = strtotime($date); + } + return date('Y/m/d', $date); + } + /** * Check if string is a valid time stamp */ @@ -358,7 +904,71 @@ abstract class MembersmanagerHelper && ($timestamp <= PHP_INT_MAX) && ($timestamp >= ~PHP_INT_MAX); } - + + + /** + * get between + * + * @param string $content The content to search + * @param string $start The starting value + * @param string $end The ending value + * @param string $default The default value if none found + * + * @return string On success / empty string on failure + * + */ + public static function getBetween($content, $start, $end, $default = '') + { + $r = explode($start, $content); + if (isset($r[1])) + { + $r = explode($end, $r[1]); + return $r[0]; + } + return $default; + } + + /** + * get all between + * + * @param string $content The content to search + * @param string $start The starting value + * @param string $end The ending value + * + * @return array On success + * + */ + public static function getAllBetween($content, $start, $end) + { + // reset bucket + $bucket = array(); + for ($i = 0; ; $i++) + { + // search for string + $found = self::getBetween($content,$start,$end); + if (self::checkString($found)) + { + // add to bucket + $bucket[] = $found; + // build removal string + $remove = $start.$found.$end; + // remove from content + $content = str_replace($remove,'',$content); + } + else + { + break; + } + // safety catch + if ($i == 500) + { + break; + } + } + // only return unique array of values + return array_unique($bucket); + } + /** * the Butler @@ -388,6 +998,10 @@ abstract class MembersmanagerHelper **/ public static function set($key, $value) { + if (!isset(self::$session) || !self::checkObject(self::$session)) + { + self::$session = JFactory::getSession(); + } // set to local memory to speed up program self::$localSession[$key] = $value; // load to session for later use @@ -399,6 +1013,10 @@ abstract class MembersmanagerHelper **/ public static function get($key, $default = null) { + if (!isset(self::$session) || !self::checkObject(self::$session)) + { + self::$session = JFactory::getSession(); + } // check if in local memory if (!isset(self::$localSession[$key])) { @@ -435,6 +1053,44 @@ abstract class MembersmanagerHelper } + /** + * open base64 string if stored as base64 + * + * @param string $data The base64 string + * @param string $key We store the string with that suffix :) + * @param string $default The default switch + * + * @return string The opened string + * + */ + public static function openValidBase64($data, $key = '__.o0=base64=Oo.__', $default = 'string') + { + // check that we have a string + if (self::checkString($data)) + { + // check if we have a key + if (self::checkString($key)) + { + if (strpos($data, $key) !== false) + { + return base64_decode(str_replace($key, '', $data)); + } + } + // fallback to this, not perfect method + if (base64_encode(base64_decode($data, true)) === $data) + { + return base64_decode($data); + } + } + // check if we should just return the string + if ('string' === $default) + { + return $data; + } + return $default; + } + + /** * the locker * @@ -779,26 +1435,53 @@ abstract class MembersmanagerHelper return $open; } + /** + * The Dynamic Data Array + * + * @var array + */ protected static $dynamicData = array(); + /** + * Set the Dynamic Data + * + * @param string $data The data to update + * @param array $placeholders The placeholders to use to update data + * + * @return string of updated data + * + */ public static function setDynamicData($data, $placeholders) { - $keyMD5 = md5($data.json_encode($placeholders)); - if (!isset(self::$dynamicData[$keyMD5])) + // make sure data is a string & placeholders is an array + if (self::checkString($data) && self::checkArray($placeholders)) { - if (self::checkArray($placeholders)) + // store in memory in case it is build multiple times + $keyMD5 = md5($data.json_encode($placeholders)); + if (!isset(self::$dynamicData[$keyMD5])) { + // remove all values that are not strings (just to be safe) + $placeholders = array_filter($placeholders, function ($val){ if (self::checkArray($val) || self::checkObject($val)) { return false; } return true; }); + // model (basic) based on logic self::setTheIF($data, $placeholders); + // update the string and store in memory self::$dynamicData[$keyMD5] = str_replace(array_keys($placeholders), array_values($placeholders), $data); } - else - { - self::$dynamicData[$keyMD5] = $data; - } + // return updated string + return self::$dynamicData[$keyMD5]; } - return self::$dynamicData[$keyMD5]; + return $data; } + /** + * Set the IF statements + * + * @param string $string The string to update + * @param array $placeholders The placeholders to use to update string + * + * @return void + * + */ protected static function setTheIF(&$string, $placeholders) { // only normal if endif @@ -843,6 +1526,15 @@ abstract class MembersmanagerHelper } } + /** + * Set the remainder IF + * + * @param array $match The match search + * @param array $placeholders The placeholders to use to match + * + * @return string of remainder + * + */ protected static function remainderIF(&$match, &$placeholders) { // default we keep nothing @@ -873,7 +1565,7 @@ abstract class MembersmanagerHelper { $keep = addcslashes($match[$length - 1], '$'); } - return $keep; + return $keep; } @@ -1148,6 +1840,39 @@ abstract class MembersmanagerHelper } + /** + * Write a file to the server + * + * @param string $path The path and file name where to safe the data + * @param string $data The data to safe + * + * @return bool true On success + * + */ + public static function writeFile($path, $data) + { + $klaar = false; + if (self::checkString($data)) + { + // open the file + $fh = fopen($path, "w"); + if (!is_resource($fh)) + { + return $klaar; + } + // write to the file + if (fwrite($fh, $data)) + { + // has been done + $klaar = true; + } + // close file. + fclose($fh); + } + return $klaar; + } + + /** * @return array of link options */ @@ -1641,6 +2366,69 @@ abstract class MembersmanagerHelper return self::$companyDetails[$method]; } + /** + * Get/load the component helper class if not already loaded + * + * @param string $_component The component element name + * + * @return string The helper class name + * + */ + public static function getHelperClass($_component) + { + // make sure we have com_ + if (strpos($_component, 'com_') !== false) + { + // get component name + $component = str_replace('com_', '', $_component); + } + else + { + // get the component name + $component = $_component; + // set the element name + $_component = 'com_' . $component; + } + // build component helper name + $componentHelper = self::safeString($component, 'F') . 'Helper'; + // check if it is already set + if (!class_exists($componentHelper)) + { + // set the correct path focus + $focus = JPATH_ADMINISTRATOR; + // check if we are in the site area + if (JFactory::getApplication()->isSite()) + { + // set admin path + $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; + // change the focus + $focus = JPATH_ROOT; + } + // set path based on focus + $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; + // check if file exist, if not try admin again. + if (file_exists($path)) + { + // make sure to load the helper + JLoader::register($componentHelper, $path); + } + // fallback option + elseif (isset($adminPath) && file_exists($adminPath)) + { + // make sure to load the helper + JLoader::register($componentHelper, $adminPath); + } + else + { + // could not find this + return false; + } + } + // success + return $componentHelper; + } + + /** * get a report * @@ -1679,6 +2467,23 @@ abstract class MembersmanagerHelper $placeholders = self::mergeArrays($placeholders); // get the ID $divID = self::randomkey(10); + // update the template with placeholders + $data = self::setDynamicData($template, $placeholders); + // make sure all placeholders are removed + if (strpos($data, '[') !== false && strpos($data, ']') !== false) + { + // get the prefix + $prefix = JComponentHelper::getParams($_component)->get('placeholder_prefix', str_replace('com_', '', $_component)); + // get the left over placeholders + $left = self::getAllBetween($data, '[' . $prefix, ']'); + if (self::checkArray($left)) + { + foreach ($left as $remove) + { + $data = str_replace('[' . $prefix . $remove . ']', '', $data); + } + } + } // get the global settings if (!self::checkObject(self::$params)) { @@ -1688,14 +2493,10 @@ abstract class MembersmanagerHelper $uikitVersion = self::$params->get('uikit_version', 2); if (3 == $uikitVersion) { - return '' . JText::_('COM_MEMBERSMANAGER_PRINT') . '
    ' . - self::setDynamicData($template, $placeholders) . - '
    '; + return '' . JText::_('COM_MEMBERSMANAGER_PRINT') . '
    ' . $data . '
    '; } // return html - return '
    ' . - self::setDynamicData($template, $placeholders) . - '
    '; + return '
    ' . $data . '
    '; } } return false; @@ -1718,40 +2519,10 @@ abstract class MembersmanagerHelper // check if we are in the correct class if ('com_membersmanager' !== $_component) { - // get component name - $component = str_replace('com_', '', $_component); - // build component helper name - $componentHelper = self::safeString($component, 'F') . 'Helper'; - // check if it is already set - if (!class_exists($componentHelper, FALSE)) - { - // set the correct path focus - $focus = JPATH_ADMINISTRATOR; - if (JFactory::getApplication()->isSite()) - { - // set admin path - $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // change the focus - $focus = JPATH_ROOT; - } - // set path based on focus - $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // check if file exist, if not try admin again. - if (file_exists($path)) - { - // make sure to load the helper - JLoader::register($componentHelper, $path); - } - elseif (isset($adminPath) && file_exists($adminPath)) // fallback option - { - // make sure to load the helper - JLoader::register($componentHelper, $adminPath); - } - } // check if the class and method exist - if (class_exists($componentHelper) && method_exists($componentHelper, 'getTemplate')) + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getTemplate')) { - return $componentHelper::getTemplate($type, $default, $target); + return $helperClass::getTemplate($type, $default, $target); } return false; } @@ -1773,56 +2544,29 @@ abstract class MembersmanagerHelper * @param string $method The type of values to return * @param string $filter The kind of filter (to return only values required) * @param string $masterkey The master key + * @param string $table The target form table + * @param int $qty The qty items to return * * @return array/object based on $method * */ - public static function getAnyFormDetails($memberID, $type = 'member', $_component = 'com_membersmanager', $method = 'array', $filter = 'none', $masterkey = 'member') + public static function getAnyFormDetails($memberID, $type = 'member', $_component = 'com_membersmanager', $method = 'array', $filter = 'none', $masterkey = 'member', $table = 'form', $qty = 0) { + // set class name + $class = self::safeString($table, 'W'); // check if we are in the correct class if ('com_membersmanager' !== $_component) { - // get component name - $component = str_replace('com_', '', $_component); - // build component helper name - $componentHelper = self::safeString($component, 'F') . 'Helper'; - // check if it is already set - if (!class_exists($componentHelper, FALSE)) - { - // set the correct path focus - $focus = JPATH_ADMINISTRATOR; - if (JFactory::getApplication()->isSite()) - { - // set admin path - $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // change the focus - $focus = JPATH_ROOT; - } - // set path based on focus - $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // check if file exist, if not try admin again. - if (file_exists($path)) - { - // make sure to load the helper - JLoader::register($componentHelper, $path); - } - elseif (isset($adminPath) && file_exists($adminPath)) - { - // make sure to load the helper - JLoader::register($componentHelper, $adminPath); - } - } // check if the class and method exist - if (class_exists($componentHelper) && method_exists($componentHelper, 'getFormDetails')) + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'get' . $class . 'Details')) { - return $componentHelper::getFormDetails($memberID, $type, 'form', $method, $filter, $masterkey); + return $helperClass::{'get' . $class . 'Details'}($memberID, $type, $table, $method, $filter, $masterkey, $qty); } - return false; } // check if the class and method exist - elseif (method_exists(__CLASS__, 'getFormDetails')) + elseif (method_exists(__CLASS__, 'get' . $class . 'Details')) { - return self::getFormDetails($memberID, $type, 'form', $method, $filter, $masterkey); + return self::{'get' . $class . 'Details'}($memberID, $type, $table, $method, $filter, $masterkey, $qty); } return false; } @@ -1843,42 +2587,11 @@ abstract class MembersmanagerHelper // check if we are in the correct class if ('com_membersmanager' !== $_component) { - // get component name - $component = str_replace('com_', '', $_component); - // build component helper name - $componentHelper = self::safeString($component, 'F') . 'Helper'; - // check if it is already set - if (!class_exists($componentHelper, FALSE)) - { - // set the correct path focus - $focus = JPATH_ADMINISTRATOR; - if (JFactory::getApplication()->isSite()) - { - // set admin path - $adminPath = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // change the focus - $focus = JPATH_ROOT; - } - // set path based on focus - $path = $focus . '/components/' . $_component . '/helpers/' . $component . '.php'; - // check if file exist, if not try admin again. - if (file_exists($path)) - { - // make sure to load the helper - JLoader::register($componentHelper, $path); - } - elseif (isset($adminPath) && file_exists($adminPath)) // fallback option - { - // make sure to load the helper - JLoader::register($componentHelper, $adminPath); - } - } // check if the class and method exist - if (class_exists($componentHelper) && method_exists($componentHelper, 'getCompanyDetails')) + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getCompanyDetails')) { - return $componentHelper::getCompanyDetails($method, $filter); + return $helperClass::getCompanyDetails($method, $filter); } - return false; } // check if the class and method exist elseif (method_exists(__CLASS__, 'getCompanyDetails')) @@ -1889,6 +2602,102 @@ abstract class MembersmanagerHelper } + /** + * Get Any chart code + * + * @param string $key The unique key/id_name + * @param string $dataTable The data table for the chart + * @param string $dataTable The details for the chart + * @param string $filter The kind of filter (to return only values required) + * @param string $_component The component element name + * + * @return string The dataTable + * + */ + public static function getAnyChartCode($key, $dataTable, $chartDetails, $filter = 'null', $_component = 'com_membersmanager') + { + // check if we are in the correct class + if ('com_membersmanager' !== $_component) + { + // check if the class and method exist + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getChartCode')) + { + return $helperClass::getChartCode($key, $dataTable, $chartDetails, $filter); + } + } + // check if the class and method exist + elseif (method_exists(__CLASS__, 'getChartCode')) + { + return self::getChartCode($key, $dataTable, $chartDetails, $filter); + } + return false; + } + + + /** + * Get Any Multi Chart dataTable + * + * @param int $memberId The member ID + * @param int $target The type of chart retrieval behavior + * @param string $key The chart key + * @param string $_component The component element name + * @param array $args Options to override chart details + * 'dataTable' => $template + * 'number' => $number + * + * @return string The dataTable + * + */ + public static function getAnyMultiChartDataTable($memberID, $target, $key = null, $_component = 'com_membersmanager', $args = null) + { + // check if we are in the correct class + if ('com_membersmanager' !== $_component) + { + // check if the class and method exist + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getMultiChartDataTable')) + { + return $helperClass::getMultiChartDataTable($memberID, $target, $key, $args); + } + } + // check if the class and method exist + elseif (method_exists(__CLASS__, 'getMultiChartDataTable')) + { + return self::getMultiChartDataTable($memberID, $target, $key, $args); + } + return false; + } + + + /** + * Get Any Available Charts + * + * @param string $key The chart key + * @param int $target The type of chart retrieval behavior + * @param string $_component The component element name + * + * @return array + * + */ + public static function getAnyAvailableCharts($key = null, $target = 1, $_component = 'com_membersmanager') + { + // check if we are in the correct class + if ('com_membersmanager' !== $_component) + { + // check if the class and method exist + if (($helperClass = self::getHelperClass($_component)) !== false && method_exists($helperClass, 'getAvailableCharts')) + { + return $helperClass::getAvailableCharts($key, $target); + } + } + // check if the class and method exist + elseif (method_exists(__CLASS__, 'getAvailableCharts')) + { + return self::getAvailableCharts($key, $target); + } + return false; + } + + /** * Get Member forms * @@ -1952,6 +2761,13 @@ abstract class MembersmanagerHelper */ protected static $memberDetails = array(); + /** + * The current return number + * + * @var int + */ + public static $returnNumber; + /** * The global details key (set per/query) * @@ -1968,11 +2784,12 @@ abstract class MembersmanagerHelper * @param string $method The type of values to return * @param string $filter The kind of filter (to return only values required) * @param string $masterkey The master key for many values in the member table + * @param int $qty The qty items to return * * @return array/object based on $method * */ - public static function getMemberDetails($id, $type = 'id', $table = 'member', $method = 'array', $filter = 'none', $masterkey = 'member') + public static function getMemberDetails($id, $type = 'id', $table = 'member', $method = 'array', $filter = 'none', $masterkey = 'member', $qty = 0) { // always make sure that we have a member column if ($table !== 'member' && $type !== $masterkey) @@ -1985,13 +2802,15 @@ abstract class MembersmanagerHelper $type = $masterkey; $table = 'member'; } + // get the user object + $user = JFactory::getUser(); // get database object $db = JFactory::getDbo(); + // get the database columns of this table + $columns = $db->getTableColumns("#__membersmanager_member", false); // if not id validate column if ($type !== 'id' && $type !== $masterkey) { - // get the database columns of this table - $columns = $db->getTableColumns("#__membersmanager_member", false); // check if the type is found if (!isset($columns[$type])) { @@ -2017,7 +2836,7 @@ abstract class MembersmanagerHelper $type = $masterkey; } // set the global key - self::$k3y = $id.$method.$filter; + self::$k3y = $id.$method.$filter.$qty; // we will check this (qty) it may not be ideal (TODO) // check if we have the member details in memory if (is_numeric($id) && $id > 0 && !isset(self::$memberDetails[self::$k3y])) { @@ -2042,6 +2861,7 @@ abstract class MembersmanagerHelper // check if we have a selection if (isset($selection) && self::checkArray($selection)) { + // do permission view purge (TODO) // set the selection $query->select($db->quoteName(array_keys($selection), array_values($selection))); // From the membersmanager_member table @@ -2051,24 +2871,48 @@ abstract class MembersmanagerHelper { self::joinMemberDetails($query, $filter, $db); } + // Implement View Level Access (if set in table) + if (!$user->authorise('core.options', '[[[com_component]]]') && isset($columns['access'])) + { + // ensure to always filter by access + $accessGroups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $accessGroups . ')'); + } // check if we have more get where details if (method_exists(__CLASS__, "whereMemberDetails")) { self::whereMemberDetails($query, $filter, $db); } + // check if we have more order details + if (method_exists(__CLASS__, "orderMemberDetails")) + { + self::orderMemberDetails($query, $filter, $db); + } + // always order so to insure last added is first by default + else + { + $query->order('a.id ASC'); + } + // limit the return + if($qty > 1) + { + $query->setLimit($qty); + } // get by type ID $query->where('a.' . $type . ' = ' . (int) $id); $db->setQuery($query); $db->execute(); - $numberRows = $db->getNumRows(); - if ($numberRows) + self::$returnNumber = $db->getNumRows(); + if (self::$returnNumber) { if ('object' == $method) { // if one to one - if ($relations == 1 || $numberRows == 1) + if ($qty == 1 || $relations == 1 || self::$returnNumber == 1) { self::$memberDetails[self::$k3y] = $db->loadObject(); + // we retrieved only 1 + self::$returnNumber = 1; } // if one to many (so we must return many) else @@ -2079,9 +2923,11 @@ abstract class MembersmanagerHelper else { // if one to one - if ($relations == 1 || $numberRows == 1) + if ($qty == 1 || $relations == 1 || self::$returnNumber == 1) { self::$memberDetails[self::$k3y] = $db->loadAssoc(); + // we retrieved only 1 + self::$returnNumber = 1; } // if one to many (so we must return many) else @@ -2098,11 +2944,11 @@ abstract class MembersmanagerHelper // check if we must model the details elseif (method_exists(__CLASS__, "modelMemberDetails")) { - self::modelMemberDetails($id, $method, $filter, $numberRows, $db); + self::modelMemberDetails($id, $method, $filter, $db); // check if we must remove some details after modeling if (method_exists(__CLASS__, "removeMemberDetails")) { - self::removeMemberDetails($id, $method, $filter, $numberRows, $db); + self::removeMemberDetails($id, $method, $filter, $db); } } } @@ -2115,19 +2961,26 @@ abstract class MembersmanagerHelper } + /** + * the global chart array + * + * @var array + * + */ + public static $globalMemberChartArray = array(); + /** * Model the member details/values * * @param object $id The the member ID * @param string $method The type of values to return * @param string $filter The kind of filter (to return only values required) - * @param int $numberRows The number of rows * @param object $db The database object * * @return void * */ - protected static function modelMemberDetails($id, $method, $filter, $numberRows, $db = null) + protected static function modelMemberDetails($id, $method, $filter, $db = null) { // check that we have values if (method_exists(__CLASS__, 'getSelection') && isset(self::$memberDetails[self::$k3y]) && self::$memberDetails[self::$k3y]) @@ -2141,7 +2994,12 @@ abstract class MembersmanagerHelper // check if we have params to model if (method_exists(__CLASS__, "paramsModelMemberDetails")) { - self::paramsModelMemberDetails($_builder, $method, $numberRows); + self::paramsModelMemberDetails($_builder, $method); + } + // check if we have subforms to model + if (method_exists(__CLASS__, "subformModelMemberDetails")) + { + self::subformModelMemberDetails($_builder, $method); } // get values that must be set (not SQL values) $builder = array_filter( @@ -2181,7 +3039,7 @@ abstract class MembersmanagerHelper if (self::checkArray($valueKeys)) { // start the modeling - if ($numberRows == 1) + if (self::$returnNumber == 1) { $object = new JObject; foreach ($valueKeys as $valueKey) @@ -2292,7 +3150,7 @@ abstract class MembersmanagerHelper } else { - if ($numberRows == 1) + if (self::$returnNumber == 1) { // work with object if ('object' === $method && isset(self::$memberDetails[self::$k3y]->{$_build[1]})) @@ -2372,19 +3230,245 @@ abstract class MembersmanagerHelper } } // check if we have labels to model - if (method_exists(__CLASS__, "labelModelMemberDetails") && property_exists(__CLASS__, 'memberParams')) + if (method_exists(__CLASS__, "labelModelMemberDetails")) { - self::labelModelMemberDetails($_builder, $method, $numberRows); + self::labelModelMemberDetails($_builder, $method); } // check if we have templates to model if (method_exists(__CLASS__, "templateModelMemberDetails") && property_exists(__CLASS__, 'memberParams')) { - self::templateModelMemberDetails($_builder, $method, $numberRows); + self::templateModelMemberDetails($_builder, $method); + } + // check if we have charts to model (must be last after all data is set) + if (method_exists(__CLASS__, "chartModelMemberDetails")) + { + self::chartModelMemberDetails($_builder, $method, $filter); + } + elseif (method_exists(__CLASS__, "multiChartModelMemberDetails")) + { + self::multiChartModelMemberDetails($_builder, $method, $filter); } } } + /** + * Label Model the member details/values + * + * @param array $builder The selection array + * @param string $method The type of values to return + * + * @return void + * + */ + protected static function labelModelMemberDetails($builder, $method) + { + // get values that must be set (not SQL values) + $builder = array_filter( + $builder, + function ($key) { + return strpos($key, 'Label->'); + }, + ARRAY_FILTER_USE_KEY + ); + // start the builder + if (self::checkArray($builder)) + { + // prep for placeholders + $f = ''; + $b = ''; + if ('placeholder' === $method) + { + // get the placeholder prefix + $prefix = self::$params->get('placeholder_prefix', 'membersmanager'); + $f = '[' . $prefix . '_'; + $b = ']'; + } + // loop builder + foreach ($builder as $build => $set) + { + // get the label key + $build = str_replace('setLabel->', '', $build); + // check if this is a single or multi array + if (self::$returnNumber == 1) + { + // work with object + if ('object' === $method) + { + self::$memberDetails[self::$k3y]->{$set} = self::setLabelModelMemberDetails($build); + } + // work with array + elseif (self::checkArray(self::$memberDetails[self::$k3y]) && isset(self::$memberDetails[self::$k3y][$f.$build.$b])) + { + self::$memberDetails[self::$k3y][$set] = self::setLabelModelMemberDetails($build); + } + } + elseif (self::checkArray(self::$memberDetails[self::$k3y])) + { + foreach (self::$memberDetails[self::$k3y] as $_nr => $details) + { + // work with object + if ('object' === $method && isset(self::$memberDetails[self::$k3y][$_nr]->{$build})) + { + self::$memberDetails[self::$k3y][$_nr]->{$set} = self::setLabelModelMemberDetails($build); + } + // work with array + elseif (self::checkArray(self::$memberDetails[self::$k3y][$_nr]) && isset(self::$memberDetails[self::$k3y][$_nr][$f.$build.$b])) + { + self::$memberDetails[self::$k3y][$_nr][$set] = self::setLabelModelMemberDetails($build); + } + } + } + } + } + } + + /** + * Set the Label to the member details/values + * + * @param string $key The key of the setting label + * + * @return mix + * + */ + protected static function setLabelModelMemberDetails($key) + { + // make sure we have the template + if (property_exists(__CLASS__, 'formParams') && isset(self::$formParams[$key]) && isset(self::$memberParams[$key]['label']) && self::checkString(self::$memberParams[$key]['label'])) + { + return JText::_(self::$memberParams[$key]['label']); + } + // check if this value is part of the admin form + $LABLE = 'COM_MEMBERSMANAGER_FORM_' . self::safeString($key, 'U') . '_LABEL'; + $label = JText::_($LABLE); + // little workaround for now + if ($LABLE === $label) + { + return self::safeString($key, 'Ww'); + } + return $label; + } + + + /** + * Multi Chart Model the member details/values + * + * @param array $builder The selection array + * @param string $method The type of values to return + * @param string $filter The kind of filter (to return only values required) + * + * @return void + * + */ + protected static function multiChartModelMemberDetails($builder, $method, $filter) + { + // get values that must be set (not SQL values) + $builder = array_filter( + $builder, + function ($key) { + return strpos($key, 'MultiChart->'); + }, + ARRAY_FILTER_USE_KEY + ); + // start the builder + if (self::checkArray($builder)) + { + // prep for placeholders + $f = ''; + $b = ''; + if ('placeholder' === $method) + { + // get the placeholder prefix + $prefix = self::$params->get('placeholder_prefix', 'membersmanager'); + $f = '[' . $prefix . '_'; + $b = ']'; + } + // set params key + // loop builder + foreach ($builder as $build => $set) + { + // get the chart key + $build = str_replace('setMultiChart->', '', $build); + // check if this is a single or multi array + if (self::$returnNumber == 1) + { + // work with object + if ('object' === $method) + { + self::$memberDetails[self::$k3y]->{$set} = self::setMultiChartModelMemberDetails(self::$memberDetails[self::$k3y]->{$f . 'id' . $b}, $build, $filter); + } + // work with array + elseif (self::checkArray(self::$memberDetails[self::$k3y])) + { + self::$memberDetails[self::$k3y][$set] = self::setMultiChartModelMemberDetails(self::$memberDetails[self::$k3y][$f . 'id' . $b], $build, $filter); + } + } + elseif (self::checkArray(self::$memberDetails[self::$k3y])) + { + foreach (self::$memberDetails[self::$k3y] as $_nr => $details) + { + // work with object + if ('object' === $method) + { + self::$memberDetails[self::$k3y][$_nr]->{$set} = self::setMultiChartModelMemberDetails(self::$memberDetails[self::$k3y][$_nr]->{$f . 'id' . $b}, $build, $filter); + } + // work with array + elseif (self::checkArray(self::$memberDetails[self::$k3y][$_nr])) + { + self::$memberDetails[self::$k3y][$_nr][$set] = self::setMultiChartModelMemberDetails(self::$memberDetails[self::$k3y][$_nr][$f . 'id' . $b], $build, $filter); + } + } + } + } + } + } + + /** + * Set the multi chart to the member details/values + * + * @param object/array $placeholders The placeholders + * @param string $key The key of the setting chart + * @param string $filter The kind of filter (to return only values required) + * + * @return string + * + */ + protected static function setMultiChartModelMemberDetails($id, $keyString, &$filter) + { + // get the key array + $keyArray = explode('\^/', $keyString); + // get the chart, the data table and the code + if (($cart = self::getAnyAvailableCharts($keyArray[0], $keyArray[2], $keyArray[1])) !== false && + ($dataTable = self::getAnyMultiChartDataTable($id, $keyArray[2], $keyArray[0], $keyArray[1])) !== '' && + ($code = self::getAnyChartCode($keyArray[0] . self::safeString($id), $dataTable, $cart['details'], $filter, $keyArray[1])) !== false) + { + if ('email' === $filter && isset($code['span'])) + { + // set to global chart array + self::$globalMemberChartArray[$code['id_name']] = $code; + // return placeholder + return $code['span']; + } + // build html + $html = array(); + $html[] = $code['div']; + $html[] = ''; + // return the chart code/html + return implode("\n", $html); + } + return ''; + } + + + /** + * The Member Name Memory + * + * @var array + */ + protected static $memberNames = array(); + /** * Get the members name * @@ -2392,12 +3476,36 @@ abstract class MembersmanagerHelper * @param int $user The user ID * @param string $name The name * @param string $surname The surname + * @param string $default The default * * @return string the members name * */ - public static function getMemberName($id, $user = null, $name = null, $surname = null) + public static function getMemberName($id = null, $user = null, $name = null, $surname = null, $default = 'No Name') { + // check if member ID is null, then get member ID + if (!$id || !is_numeric($id)) + { + if (!$user || !is_numeric($user) || ($id = self::getVar('member', $user, 'user', 'id', '=', 'membersmanager')) === false || !is_numeric($id) || $id == 0) + { + // check if a was name given + if (self::checkstring($name)) + { + $default = $name; + } + // always set surname if given + if (self::checkString($surname)) + { + $default += ' ' . $surname; + } + return $default; + } + } + // check if name in memory + if (isset(self::$memberNames[$id])) + { + return self::$memberNames[$id]; + } // always get surname if (!self::checkString($surname)) { @@ -2409,19 +3517,125 @@ abstract class MembersmanagerHelper // check name given if (self::checkstring($name)) { - return $name . ' ' . $surname; + $memberName = $name . ' ' . $surname; } // check user given - elseif ((is_numeric($user) && $user > 0) || (is_numeric($id) && $id > 0 && ($user = self::getVar('member', $id, 'id', 'user', '=', 'membersmanager')) !== false && $user > 0)) + elseif ((is_numeric($user) && $user > 0) || (($user = self::getVar('member', $id, 'id', 'user', '=', 'membersmanager')) !== false && $user > 0)) { - return JFactory::getUser($user)->name . ' ' . $surname; + $memberName = JFactory::getUser($user)->name . ' ' . $surname; } // get the name - elseif (is_numeric($id) && $id > 0 && ($name = self::getVar('member', $id, 'id', 'name', '=', 'membersmanager')) !== false && self::checkstring($name)) + elseif (($name = self::getVar('member', $id, 'id', 'name', '=', 'membersmanager')) !== false && self::checkstring($name)) { - return $name . ' ' . $surname; + $memberName = $name . ' ' . $surname; } - return JText::_('COM_MEMBERSMANAGER_NO_NAME'); + // load to memory + if (isset($memberName)) + { + self::$memberNames[$id] = $memberName; + // return member name + return $memberName; + } + return $default; + } + + /** + * The Member Email Memory + * + * @var array + */ + protected static $memberEmails = array(); + + /** + * Get the members email + * + * @param int $id The member ID + * @param int $user The user ID + * @param string $default The default + * + * @return string the members email + * + */ + public static function getMemberEmail($id = null, $user = null, $default = '') + { + // check if member ID is null, then get member ID + if (!$id || !is_numeric($id)) + { + if (!$user || !is_numeric($user) || ($id = self::getVar('member', $user, 'user', 'id')) === false) + { + return $default; + } + } + // check if email in memory + if (isset(self::$memberEmails[$id])) + { + return self::$memberEmails[$id]; + } + // check user given + if ((is_numeric($user) && $user > 0) || (is_numeric($id) && $id > 0 && ($user = self::getVar('member', $id, 'id', 'user', '=', 'membersmanager')) !== false && $user > 0)) + { + $memberEmail = JFactory::getUser($user)->email; + } + // get the email + elseif (($email = self::getVar('member', $id, 'id', 'email', '=', 'membersmanager')) !== false && self::checkstring($email)) + { + $memberEmail = $email; + } + // load to memory + if (isset($memberEmail)) + { + self::$memberEmails[$id] = $memberEmail; + // return found email + return $memberEmail; + } + return $default; + } + + + /** + * get all components linked + * + * @return array of all components + * + */ + public static function getAllComponents($relation = null, $types = array('Info','Assessment')) + { + // build components array + $components = array(); + // search if the types are set and active + foreach ($types as $type) + { + if (method_exists(__CLASS__, 'get' . $type. 'Components') && ($_components = self::{'get' . $type. 'Components'}(null, null, $relation)) !== false && self::checkArray($_components)) + { + $components = self::mergeArrays(array($components, $_components)); + } + } + // if we found components return + if (self::checkArray($components)) + { + return $components; + } + return false; + } + + + /** + * get active component name + * + * @return string of component name + * + */ + public static function getComponentName($_component, $types = array('Info','Assessment')) + { + // search if the types are set and active + foreach ($types as $type) + { + if (method_exists(__CLASS__, 'get' . $type. 'ComponentName') && ($name = self::{'get' . $type. 'ComponentName'}($_component)) !== false) + { + return $name; + } + } + return false; } @@ -2433,9 +3647,9 @@ abstract class MembersmanagerHelper /** * Get available infos based on type */ - public static function getInfoAvaillable($type, $account, $multiDimensionalAllowed = true) + public static function getInfoAvaillable($types, $account, $multiDimensionalAllowed = true) { - $infos = self::getInfoComponents($type, $account); + $infos = self::getInfoComponents($types, $account); // check if we found components if (self::checkArray($infos)) { @@ -2463,9 +3677,31 @@ abstract class MembersmanagerHelper if (!isset($bucketInfos[$infoTypeName])) { $bucketInfos[$infoTypeName] = array(); + $bucketInfos[$infoTypeName][] = $component; + } + // check if this is an array set + elseif (self::checkArray($bucketInfos[$infoTypeName])) + { + // set data (one to many) + $bucketInfos[$infoTypeName][] = $component; + } + // check if this is an array set + elseif (self::checkObject($bucketInfos[$infoTypeName])) + { + $bucket_key = $infoTypeName . ' *'; + // start array if not already set + if (!isset($bucketInfos[$bucket_key])) + { + $bucketInfos[$bucket_key] = array(); + $bucketInfos[$bucket_key][] = $component; + } + // check if this is an array set + elseif (self::checkArray($bucketInfos[$bucket_key])) + { + // set data (one to many) + $bucketInfos[$bucket_key][] = $component; + } } - // set data (one to many) - $bucketInfos[$infoTypeName][] = $component; } } // return the info bucket @@ -2474,12 +3710,37 @@ abstract class MembersmanagerHelper return false; } + /** + * Get type info component name + */ + public static function getInfoComponentName($_component) + { + // see if we have components in memory + if (!self::checkArray(self::$infoComponents)) + { + // get list of components + self::$infoComponents = self::setInfoComponents(); + } + // make sure we have components + if (self::checkArray(self::$infoComponents)) + { + foreach (self::$infoComponents as $component) + { + if ($component->element === $_component) + { + return $component->name; + } + } + } + return false; + } + /** * Get type info names */ - public static function getTypeInfosNames($type, $account, $as = 'string') + public static function getTypeInfosNames($types, $account, $as = 'string') { - $infos = self::getInfoAvaillable($type, $account); + $infos = self::getInfoAvaillable($types, $account); $names = array(); if (self::checkArray($infos)) { @@ -2508,27 +3769,57 @@ abstract class MembersmanagerHelper /** * Get info components */ - public static function getInfoComponents($type = null, $account = null) + public static function getInfoComponents($types = null, $account = null, $relation = null) { + // see if we have components in memory if (!self::checkArray(self::$infoComponents)) { - // get list of Extensions + // get list of components self::$infoComponents = self::setInfoComponents(); } - // filter by type & account - if ($type && $account && self::checkArray(self::$infoComponents)) + // make sure we have components + if (self::checkArray(self::$infoComponents)) { - // filter out the components we need - return array_filter( - self::$infoComponents, - function ($component) use ($type, $account) { - // check if the component is available to this type of member - return ((isset($component->params->membersmanager_target_type) && in_array($type, (array) $component->params->membersmanager_target_type)) && - (isset($component->params->membersmanager_target_account) && in_array($account, (array) $component->params->membersmanager_target_account))); - } - ); + // convert type json to array + if ($types && self::checkJson($types)) + { + $types = json_decode($types, true); + } + // convert type int to array + if ($types && is_numeric($types) && $types > 0) + { + $types = array($types); + } + // filter by type & account + if ($types && self::checkArray($types) && $account) + { + // our little function to check if two arrays intersect on values + $intersect = function ($a, $b) { $b = array_flip($b); foreach ($a as $v) { if (isset($b[$v])) return true; } return false; }; + // filter out the components we need + return array_filter( + self::$infoComponents, + function ($component) use ($types, $account, $relation, $intersect) { + // check if the component is available to this type of member + return ((isset($component->params->membersmanager_target_type) && $intersect($types, (array) $component->params->membersmanager_target_type)) && + (isset($component->params->membersmanager_target_account) && in_array($account, (array) $component->params->membersmanager_target_account)) && + (!$relation || (is_int($relation) && $relation == $component->params->membersmanager_relation_type))); + } + ); + } + elseif (is_int($relation)) + { + // filter out the components we need + return array_filter( + self::$infoComponents, + function ($component) use ($relation) { + // check if the component is available to this relation + return ($relation == $component->params->membersmanager_relation_type); + } + ); + } + return self::$infoComponents; } - return self::$infoComponents; + return false; } /** @@ -2553,10 +3844,11 @@ abstract class MembersmanagerHelper $listComponents = array_filter( $listComponents, function ($component) { - if (strpos($component->params, 'activate_membersmanager_info') !== false) + if (self::checkJson($component->params) && strpos($component->params, 'activate_membersmanager_info') !== false) { // check if this component is active - return json_decode($component->params)->activate_membersmanager_info; + $component->params = json_decode($component->params); + return $component->params->activate_membersmanager_info; } return false; } @@ -2568,16 +3860,27 @@ abstract class MembersmanagerHelper $lang = JFactory::getLanguage(); foreach ($listComponents as $listComponent) { - // lets do a quick params setup (to objects) - $listComponent->params = json_decode($listComponent->params); - // try to load the translation - $lang->load($listComponent->element, JPATH_ADMINISTRATOR, null, false, true); - // translate the extension name if possible - $listComponent->name = JText::_($listComponent->name); - // translate the info type name - if (isset($listComponent->params->info_type_name)) + if (isset($listComponent->params)) { - $listComponent->params->info_type_name = JText::_(strtoupper($listComponent->element) . '_CONFIG_' . $listComponent->params->info_type_name); + // convert params to object + if (self::checkJson($listComponent->params)) + { + // lets do a quick params setup (to objects) + $listComponent->params = json_decode($listComponent->params); + } + // check that we have an object + if (self::checkObject($listComponent->params)) + { + // try to load the translation + $lang->load($listComponent->element, JPATH_ADMINISTRATOR, null, false, true); + // translate the extension name if possible + $listComponent->name = JText::_($listComponent->name); + // translate the info type name + if (isset($listComponent->params->info_type_name)) + { + $listComponent->params->info_type_name = JText::_(strtoupper($listComponent->element) . '_CONFIG_' . $listComponent->params->info_type_name); + } + } } } return $listComponents; @@ -2595,9 +3898,9 @@ abstract class MembersmanagerHelper /** * Get available assessments based on type */ - public static function getAssessmentAvaillable($type, $account, $multiDimensionalAllowed = true) + public static function getAssessmentAvaillable($types, $account, $multiDimensionalAllowed = true) { - $assessments = self::getAssessmentComponents($type, $account); + $assessments = self::getAssessmentComponents($types, $account); // check if we found components if (self::checkArray($assessments)) { @@ -2625,9 +3928,31 @@ abstract class MembersmanagerHelper if (!isset($bucketAssessments[$assessmentTypeName])) { $bucketAssessments[$assessmentTypeName] = array(); + $bucketAssessments[$assessmentTypeName][] = $component; + } + // check if this is an array set + elseif (self::checkArray($bucketAssessments[$assessmentTypeName])) + { + // set data (one to many) + $bucketAssessments[$assessmentTypeName][] = $component; + } + // check if this is an array set + elseif (self::checkObject($bucketAssessments[$assessmentTypeName])) + { + $bucket_key = $assessmentTypeName . ' *'; + // start array if not already set + if (!isset($bucketAssessments[$bucket_key])) + { + $bucketAssessments[$bucket_key] = array(); + $bucketAssessments[$bucket_key][] = $component; + } + // check if this is an array set + elseif (self::checkArray($bucketAssessments[$bucket_key])) + { + // set data (one to many) + $bucketAssessments[$bucket_key][] = $component; + } } - // set data (one to many) - $bucketAssessments[$assessmentTypeName][] = $component; } } // return the assessment bucket @@ -2636,12 +3961,37 @@ abstract class MembersmanagerHelper return false; } + /** + * Get type assessment component name + */ + public static function getAssessmentComponentName($_component) + { + // see if we have components in memory + if (!self::checkArray(self::$assessmentComponents)) + { + // get list of components + self::$assessmentComponents = self::setAssessmentComponents(); + } + // make sure we have components + if (self::checkArray(self::$assessmentComponents)) + { + foreach (self::$assessmentComponents as $component) + { + if ($component->element === $_component) + { + return $component->name; + } + } + } + return false; + } + /** * Get type assessment names */ - public static function getTypeAssessmentsNames($type, $account, $as = 'string') + public static function getTypeAssessmentsNames($types, $account, $as = 'string') { - $assessments = self::getAssessmentAvaillable($type, $account); + $assessments = self::getAssessmentAvaillable($types, $account); $names = array(); if (self::checkArray($assessments)) { @@ -2670,27 +4020,57 @@ abstract class MembersmanagerHelper /** * Get assessment components */ - public static function getAssessmentComponents($type = null, $account = null) + public static function getAssessmentComponents($types = null, $account = null, $relation = null) { + // see if we have components in memory if (!self::checkArray(self::$assessmentComponents)) { - // get list of Extensions + // get list of components self::$assessmentComponents = self::setAssessmentComponents(); } - // filter by type & account - if ($type && $account && self::checkArray(self::$assessmentComponents)) + // make sure we have components + if (self::checkArray(self::$assessmentComponents)) { - // filter out the components we need - return array_filter( - self::$assessmentComponents, - function ($component) use ($type, $account) { - // check if the component is available to this type of member - return ((isset($component->params->membersmanager_target_type) && in_array($type, (array) $component->params->membersmanager_target_type)) && - (isset($component->params->membersmanager_target_account) && in_array($account, (array) $component->params->membersmanager_target_account))); - } - ); + // convert type json to array + if ($types && self::checkJson($types)) + { + $types = json_decode($types, true); + } + // convert type int to array + if ($types && is_numeric($types) && $types > 0) + { + $types = array($types); + } + // filter by type & account + if ($types && self::checkArray($types) && $account) + { + // our little function to check if two arrays intersect on values + $intersect = function ($a, $b) { $b = array_flip($b); foreach ($a as $v) { if (isset($b[$v])) return true; } return false; }; + // filter out the components we need + return array_filter( + self::$assessmentComponents, + function ($component) use ($types, $account, $relation, $intersect) { + // check if the component is available to this type of member + return ((isset($component->params->membersmanager_target_type) && $intersect($types, (array) $component->params->membersmanager_target_type)) && + (isset($component->params->membersmanager_target_account) && in_array($account, (array) $component->params->membersmanager_target_account)) && + (!$relation || (is_int($relation) && $relation == $component->params->membersmanager_relation_type))); + } + ); + } + elseif (is_int($relation)) + { + // filter out the components we need + return array_filter( + self::$assessmentComponents, + function ($component) use ($relation) { + // check if the component is available to this relation + return ($relation == $component->params->membersmanager_relation_type); + } + ); + } + return self::$assessmentComponents; } - return self::$assessmentComponents; + return false; } /** @@ -2715,10 +4095,11 @@ abstract class MembersmanagerHelper $listComponents = array_filter( $listComponents, function ($component) { - if (strpos($component->params, 'activate_membersmanager_assessment') !== false) + if (self::checkJson($component->params) && strpos($component->params, 'activate_membersmanager_assessment') !== false) { // check if this component is active - return json_decode($component->params)->activate_membersmanager_assessment; + $component->params = json_decode($component->params); + return $component->params->activate_membersmanager_assessment; } return false; } @@ -2730,16 +4111,27 @@ abstract class MembersmanagerHelper $lang = JFactory::getLanguage(); foreach ($listComponents as $listComponent) { - // lets do a quick params setup (to objects) - $listComponent->params = json_decode($listComponent->params); - // try to load the translation - $lang->load($listComponent->element, JPATH_ADMINISTRATOR, null, false, true); - // translate the extension name if possible - $listComponent->name = JText::_($listComponent->name); - // translate the assessment type name - if (isset($listComponent->params->assessment_type_name)) + if (isset($listComponent->params)) { - $listComponent->params->assessment_type_name = JText::_(strtoupper($listComponent->element) . '_CONFIG_' . $listComponent->params->assessment_type_name); + // convert params to object + if (self::checkJson($listComponent->params)) + { + // lets do a quick params setup (to objects) + $listComponent->params = json_decode($listComponent->params); + } + // check that we have an object + if (self::checkObject($listComponent->params)) + { + // try to load the translation + $lang->load($listComponent->element, JPATH_ADMINISTRATOR, null, false, true); + // translate the extension name if possible + $listComponent->name = JText::_($listComponent->name); + // translate the assessment type name + if (isset($listComponent->params->assessment_type_name)) + { + $listComponent->params->assessment_type_name = JText::_(strtoupper($listComponent->element) . '_CONFIG_' . $listComponent->params->assessment_type_name); + } + } } } return $listComponents; @@ -2762,7 +4154,7 @@ abstract class MembersmanagerHelper public static function loadDynamicTabs(&$item, $view = 'member', $return = '') { // only loads if type and account is set - if (is_numeric($item->type) && $item->type > 0 && is_numeric($item->account) && $item->account > 0) + if (isset($item->type) && (self::checkJson($item->type) || (is_numeric($item->type) && $item->type > 0) || self::checkArray($item->type)) && is_numeric($item->account) && $item->account > 0) { // get all the available component calling metods $class = new ReflectionClass('MembersmanagerHelper'); @@ -2775,9 +4167,12 @@ abstract class MembersmanagerHelper return false; } ); + // get the database object + $db = JFactory::getDBO(); // set the tabs $tabs = array(); $layout = array(); + $script = array(); if (self::checkArray($methods)) { foreach ($methods as $method) @@ -2797,7 +4192,12 @@ abstract class MembersmanagerHelper { if (($ids = self::getVars('form', $item->id, $view, 'id', 'IN', str_replace('com_', '', $comp->element))) !== false && self::checkArray($ids)) { - $tables[] = self::getTabLinksTable($ids, $item, $comp, $view, $return); + // load the table + $tables[] = self::getTabLinksTable($ids, $item, $comp, $view, $return, $db); + } + elseif (($tmp = self::getTabLinksTable(null, $item, $comp, $view, $return, $db)) !== false) + { + $tables[] = $tmp; } } // load the tables to the layout @@ -2835,10 +4235,11 @@ abstract class MembersmanagerHelper // check if user are allowed to edit form values or create form values if (($id > 0 && JFactory::getUser()->authorise('form.edit', $component->element . '.form.' . (int) $id)) || ($id == 0 && JFactory::getUser()->authorise('form.create', $component->element))) { - $fields = self::getTabFields($id, $component); + $fields = self::getTabFields($id, $component, $script); // load the fields to the layout if (self::checkString($fields)) { + // add fields $layout[$_name] = $fields; } // add layout to tabs @@ -2853,14 +4254,22 @@ abstract class MembersmanagerHelper } } } - // add layout to tabs + // add remainder layout to tabs if (self::checkArray($layout)) { $tabs[] = self::setTab($layout, $view); } + // add the Relationship tab + self::setRelationshipTab($item, $view, $return, $tabs); // check if we have tabs if (self::checkArray($tabs)) { + // load the script if found + if (self::checkArray($script)) + { + $document = JFactory::getDocument(); + $document->addScriptDeclaration(implode("\n", $script)); + } return implode("\n", $tabs); } } @@ -2868,15 +4277,132 @@ abstract class MembersmanagerHelper } /** - * get the tabe fields + * set the relationship tab * - * @param int $id The item id - * @param object $component The target component details + * @param object $item Data for the form + * @param string $view The view name + * @param string $return The return value if found + * @param array $tabs The exiting tabs array + * + * @return void + * + */ + protected static function setRelationshipTab(&$item, &$view, &$return, &$tabs) + { + // get DB + $db = JFactory::getDBO(); + // check if there is relationships and members in those relationships + if (self::checkObject($item) && isset($item->type) && ($relation_types = self::getRelationshipsByTypes($item->type, $db)) !== false) + { + // get the members already selected relationships + $relation_selected = (isset($item->id) && $item->id > 0) ? self::getRelationshipsByMember($item->id, $db) : false; + // build the fields + $null = null; + $headers = array(); + $form = array(); + foreach ($relation_types as $id => $type) + { + // get the field selection + $selected = ($relation_selected && isset($relation_selected[$id])) ? $relation_selected[$id] : ''; + // set the field note headers + $headers[$id] = self::getRelationshipField($type->name, $type->description, $selected, $null); + // set the field + $form[$id] = self::getRelationshipField($type->name, $type->field_type, $selected, $type->members); + } + // divide the fields in two + $form = self::array_partition($form, 2, true); + // load the field layouts + foreach($form as $key => $fields) + { + $layout[$key] = ''; + foreach ($fields as $pointer => $field) + { + // first set the header + $layout[$key] .= (isset($headers[$pointer])) ? '
    ' . $headers[$pointer]->label . '
    ': ''; + // first set the header + $layout[$key] .= '
    '; + $layout[$key] .= '
    ' . $field->label . '
    '; + $layout[$key] .= '
    ' . $field->input . '
    '; + $layout[$key] .= '
    '; + } + } + // update tabs + $tabs[] = self::setTab($layout, $view, JText::_('COM_MEMBERSMANAGER_RELATIONSHIPS'), 6, false); + } + } + + /** + * get the relationship field + * + * @param string $name The field name + * @param int/string $type The type if int or description if string + * @param array $selected The selected values * * @return string * */ - protected static function getTabFields($id, &$component) + protected static function getRelationshipField(&$name, &$type, &$selected, &$values) + { + switch ($type) + { + case 1: + // build checkboxes + $attributes = array( + 'type' => 'checkboxes', + 'name' => 'relationship_mapping_' . self::safeString($name), + 'label' => $name, + 'class' => 'list_class', + 'description' => 'COM_MEMBERSMANAGER_MAKE_A_SELECTION_TO_CREATE_A_RELATIONSHIP'); + break; + case 2: + // build list + $attributes = array( + 'type' => 'list', + 'name' => 'relationship_mapping_' . self::safeString($name), + 'label' => $name, + 'multiple' => true, + 'class' => 'list_class', + 'description' => 'COM_MEMBERSMANAGER_MAKE_A_SELECTION_TO_CREATE_A_RELATIONSHIP'); + break; + default: + // build a note + $attributes = array( + 'type' => 'note', + 'name' => 'relationship_mapping_note_' . self::safeString($name), + 'label' => $name, + 'class' => 'alert'); + if (self::checkString($type)) + { + $attributes['description'] = $type; + } + break; + } + // set options + $options = null; + if (self::checkArray($values)) + { + // start the building the options + $options = array(); + // load relationship options from array + foreach($values as $value) + { + $options[(int) $value] = self::getMemberName($value); + } + } + return self::getFieldObject($attributes, $selected, $options); + } + + /** + * get the tab fields + * + * @param int $id The item id + * @param object $component The target component details + * @param array $document The document array to load script + * + * @return string + * + */ + protected static function getTabFields($id, &$component, &$document) { // build the rows $rows = ''; @@ -2886,6 +4412,8 @@ abstract class MembersmanagerHelper // get the fields for this form if (($fields = JComponentHelper::getParams($component->element)->get('edit_fields', false)) !== false && self::checkObject($fields)) { + // load the fields script + self::getTabFieldsScript($component->element, $document); // add the id field if the id was found (but hidden) if ($id > 0) { @@ -2905,6 +4433,57 @@ abstract class MembersmanagerHelper return $rows; } + + /** + * get the tab fields script + * + * @param object $component The target component + * @param array $document The document array to load script + * + * @return string + * + */ + protected static function getTabFieldsScript(&$_component, &$document) + { + // get component name + $component = str_replace('com_', '', $_component); + // values to change in script + $replace = array( + 'jform_' => $component . '_', + 'updateFieldRequired' => $component . 'updateFieldRequired', + 'isSet' => $component . 'isSet', + 'vvvvv' => $component . 'uuuu' + ); + // normal path to view javascript file + $script_path = JPATH_ADMINISTRATOR . '/components/' . $_component . '/models/forms/form.js'; + // load the javascript for this view + if (file_exists($script_path) && ($script = self::getFileContents($script_path, false)) !== false) + { + // now update the script and add to document + $document[] = str_replace(array_keys($replace), array_values($replace), $script); + } + // normal path to view file + $view_path = JPATH_ADMINISTRATOR . '/components/' . $_component . '/views/form/tmpl/edit.php'; + // load the javascript form this view + if (file_exists($view_path) && ($w_script = self::getFileContents($view_path, false)) !== false) + { + // get all script from view + $a_script = self::getAllBetween($w_script, ''); + // check if we found any + if (self::checkArray($a_script)) + { + foreach ($a_script as $_script) + { + if (strpos($_script, '// waiting spinner') === false && strpos($_script, 'element); + // get the database columns of this table + $columns = $db->getTableColumns("#__" . $component . "_form", false); // get the global settings $params = JComponentHelper::getParams($comp->element); // get the profile fields @@ -2931,40 +4514,63 @@ abstract class MembersmanagerHelper { $rows[] = '' . $create_button . ''; } - // build the links - foreach ($ids as $id) + // see if id's are found + if (self::checkArray($ids)) { - if (self::checkObject($profile_fields)) + // build the links + foreach ($ids as $id) { - // the bucket - $bucket = array(); - foreach ($profile_fields as $profile) + if (self::checkObject($profile_fields)) { - $bucket[$profile->field] = self::getVar('form', $id, 'id', $profile->field, '=', str_replace('com_', '', $comp->element)); + // the bucket + $bucket = array(); + foreach ($profile_fields as $profile) + { + $bucket[$profile->field] = self::getVar('form', $id, 'id', $profile->field, '=', $component); + } + $rows[] = '' . implode(', ', $bucket) . self::getEditButton($id, 'form', 'forms', $_return, $comp->element) . ''; + } + else + { + // get creating date + $created = self::getVar('form', $id, 'id', 'created', '=', $component); + // set name + $name = self::fancyDayTimeDate($created); + // check if there is a name in table + if (isset($columns['name'])) + { + // get name + $name = self::getVar('form', $id, 'id', 'name', '=', $component) . ' (' . $name . ')'; + } + elseif (isset($columns['title'])) + { + // get name + $name = self::getVar('form', $id, 'id', 'title', '=', $component) . ' (' . $name . ')'; + } + $rows[] = '' . $name . self::getEditButton($id, 'form', 'forms', $_return, $comp->element) . ''; } - $rows[] = '' . implode(', ', $bucket) . self::getEditButton($id, 'form', 'forms', $_return, $comp->element) . ''; - } - else - { - $created = self::getVar('form', $id, 'id', 'created', '=', str_replace('com_', '', $comp->element)); - $rows[] = '' . self::fancyDayTimeDate($created) . self::getEditButton($id, 'form', 'forms', $_return, $comp->element) . ''; } } - // set the header - $head = array($comp->name); - // return the table - return self::setSubformTable($head, $rows, $view . '_' . $comp->name); + // check if we have rows + if (self::checkArray($rows)) + { + // set the header + $head = array($comp->name); + // return the table + return self::setSubformTable($head, $rows, $view . '_' . $comp->name); + } + return false; } /** * get the form fields * - * @param string $layout The layout array - * @param string $code The tab/view code name - * @param string $name The tab name - * @param int $span The span trigger - * @param bool $alert Show the alert + * @param string $layout The layout array + * @param string $code The tab/view code name + * @param string $name The tab name + * @param int $span The span trigger + * @param bool $alert Show the alert * * @return string * @@ -2976,7 +4582,7 @@ abstract class MembersmanagerHelper { $name = implode(' & ', array_keys($layout)); } -$tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); + $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); $tmp .= PHP_EOL . '
    '; if (count((array) $layout) == 1) { @@ -3066,7 +4672,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); * @param object $date The main Data * @param string $view The view name * - * @return string + * @return void * */ public static function saveDynamicValues(&$data, $view = 'member') @@ -3083,7 +4689,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } ); // check if we have methods - if (self::checkArray($methods)) + if (self::checkArray($methods) && isset($data['type'], $data['account'])) { // get the app object $app = JFactory::getApplication(); @@ -3208,7 +4814,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); $fieldActive['rules'] = 'rules'; // get the database columns of this table $columns = $db->getTableColumns("#__" . $component . "_form", false); - // no make sure the fields that are not editable are removed (so can't be updated via this form) + // now make sure the fields that are not editable are removed (so can't be updated via this form) foreach(array_keys($columns) as $field) { if (!isset($fieldActive[$field])) @@ -3259,6 +4865,249 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } } + + /** + * save the relationships + * + * @param object $date The main Data + * + * @return void + * + */ + public static function saveRelationships(&$data) + { + // get the app object + $app = JFactory::getApplication(); + // get the user object + $user = JFactory::getUser(); + // check if user may edit + if (0) // !$user->authorise('member.edit.type', 'com_membersmanager.member.' . (int) $data['id'])) (TODO) + { + $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_THIS_MEMBER_RELATIONSHIPS_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR'), 'warning'); + return; + } + // check if there is relationships and members in those relationships + if (self::checkArray($data) && isset($data['id']) && is_numeric($data['id']) && $data['id'] > 0 && isset($data['type']) + && ($relation_types = self::getRelationshipsByTypes($data['type'], $db, true)) !== false) + { + // get database object + $db = JFactory::getDbo(); + // get the post object + $post = JFactory::getApplication()->input->post; + // Create a new query object. + $query = $db->getQuery(true); + // build insert query + $query->insert($db->quoteName('#__membersmanager_relation_map')); + // Insert columns. + $columns = array('relation', 'member', 'type'); + $query->columns($db->quoteName($columns)); + // found values + $found = false; + // start looping the methods + foreach ($relation_types as $type) + { + // delete all previous set relationships of this member and type + self::deleteRelationship($data['id'], $type->id, $db); + // get components + $get = 'relationship_mapping_' . self::safeString($type->name); + // get the posted date if there were any + $_values = $post->get($get, array(), 'array'); + // check if we found relationships + if (self::checkArray($_values)) + { + // build the values + foreach ($_values as $_value) + { + if (is_numeric($_value) && $_value > 0) + { + $query->values((int) $_value . ',' . (int) $data['id'] . ',' . (int) $type->id); + } + } + $found = true; + } + } + // save relationship if found + if ($found) + { + // Set the query using our newly populated query object and execute it. + $db->setQuery($query); + $db->execute(); + } + } + } + + /** + * delete the relationships + * + * @param int $member The member ID + * @param int $type The type ID + * + * @return void + * + */ + public static function deleteRelationship(&$member, &$type, &$db) + { + $query = $db->getQuery(true); + // delete all types the are linked to this member + $conditions = array( + $db->quoteName('member') . ' = ' . (int) $member, + $db->quoteName('type') . ' = ' . (int) $type + ); + $query->delete($db->quoteName('#__membersmanager_relation_map')); + $query->where($conditions); + $db->setQuery($query); + $db->execute(); + } + + + /** + * update the type map, for quick search + * + * @param int $member The member ID + * @param string/array $types The types + * + * @return void + * + */ + public static function updateTypes(&$member, $types = null) + { + // get the app object + $app = JFactory::getApplication(); + // get the user object + $user = JFactory::getUser(); + // check if user may edit + if (!$user->authorise('member.edit.type', 'com_membersmanager.member.' . (int) $member)) + { + $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_THIS_MEMBER_TYPE_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR'), 'warning'); + return; + } + // get database object + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + // delete all types the are linked to this member + $conditions = array( + $db->quoteName('member') . ' = ' . (int) $member + ); + $query->delete($db->quoteName('#__membersmanager_type_map')); + $query->where($conditions); + $db->setQuery($query); + $db->execute(); + // now set the new values + if (self::checkArray($types)) + { + // Create a new query object. + $query = $db->getQuery(true); + // Insert columns. + $columns = array('member', 'type'); + // build insert query + $query->insert($db->quoteName('#__membersmanager_type_map')); + $query->columns($db->quoteName($columns)); + // build the values + foreach ($types as $type) + { + $query->values((int) $member . ',' . (int) $type); + } + // Set the query using our newly populated query object and execute it. + $db->setQuery($query); + $db->execute(); + } + } + + + /** + * Array Partitioning Function + * + * @link http://php.net/manual/en/function.array-chunk.php#75022 + * Thanks to azspot at gmail dot com + * + * @param array $array

    + * The array to work on + *

    + * @param int $size

    + * The size of each chunk + *

    + * @param bool $preserve_keys [optional]

    + * When set to TRUE keys will be preserved. + * Default is FALSE which will reindex the chunk numerically + *

    + * + * @return array a multidimensional numerically indexed array, starting with zero, + * with each dimension containing size elements. + */ + public static function array_partition($array, $size, $preserve_keys = FALSE) + { + // set some key values + $arraylen = count((array) $array ); + $partlen = floor( $arraylen / $size ); + $partrem = $arraylen % $size; + // start the partition builder + $partition = array(); + $offset = 0; + for ($sizex = 0; $sizex < $size; $sizex++) + { + // get the partition length + $length = ($sizex < $partrem) ? $partlen + 1 : $partlen; + // set the partition values + $partition[$sizex] = array_slice($array, $offset, $length, $preserve_keys); + // update the offset + $offset += $length; + } + return $partition; + } + + + /** + * get the content of a file + * + * @param string $path The path to the file + * @param string/bool $none The return value if no content was found + * + * @return string On success + * + */ + public static function getFileContents($path, $none = '') + { + if (self::checkString($path)) + { + // use basic file get content for now + if (($content = @file_get_contents($path)) !== FALSE) + { + return $content; + } + // use curl if available + elseif (function_exists('curl_version')) + { + // start curl + $ch = curl_init(); + // set the options + $options = array(); + $options[CURLOPT_URL] = $path; + $options[CURLOPT_USERAGENT] = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; + $options[CURLOPT_RETURNTRANSFER] = TRUE; + $options[CURLOPT_SSL_VERIFYPEER] = FALSE; + // load the options + curl_setopt_array($ch, $options); + // get the content + $content = curl_exec($ch); + // close the connection + curl_close($ch); + // return if found + if (self::checkString($content)) + { + return $content; + } + } + elseif (property_exists('MembersmanagerHelper', 'curlErrorLoaded') && !self::$curlErrorLoaded) + { + // set the notice + JFactory::getApplication()->enqueueMessage(JText::_('COM_MEMBERSMANAGER_HTWOCURL_NOT_FOUNDHTWOPPLEASE_SETUP_CURL_ON_YOUR_SYSTEM_OR_BMEMBERSMANAGERB_WILL_NOT_FUNCTION_CORRECTLYP'), 'Error'); + // load this notice only once + self::$curlErrorLoaded = true; + } + } + return $none; + } + public static function jsonToString($value, $sperator = ", ", $table = null, $id = 'id', $name = 'name') { @@ -3309,7 +5158,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Load the Component xml manifest. + * Load the Component xml manifest. **/ public static function manifest() { @@ -3318,12 +5167,12 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Joomla version object + * Joomla version object **/ protected static $JVersion; /** - * set/get Joomla version + * set/get Joomla version **/ public static function jVersion() { @@ -3336,7 +5185,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Load the Contributors details. + * Load the Contributors details. **/ public static function getContributors() { @@ -3382,7 +5231,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Get any component's model + * Get any component's model **/ public static function getModel($name, $path = JPATH_COMPONENT_SITE, $component = 'Membersmanager', $config = array()) { @@ -3426,9 +5275,9 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Add to asset Table + * Add to asset Table */ - public static function setAsset($id,$table) + public static function setAsset($id, $table, $inherit = true) { $parent = JTable::getInstance('Asset'); $parent->loadByName('com_membersmanager'); @@ -3445,8 +5294,6 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); if ($error) { - $this->setError($error); - return false; } else @@ -3462,7 +5309,7 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); $asset->name = $name; $asset->title = $title; // get the default asset rules - $rules = self::getDefaultAssetRules('com_membersmanager',$table); + $rules = self::getDefaultAssetRules('com_membersmanager', $table, $inherit); if ($rules instanceof JAccessRules) { $asset->rules = (string) $rules; @@ -3490,55 +5337,62 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Gets the default asset Rules for a component/view. + * Gets the default asset Rules for a component/view. */ - protected static function getDefaultAssetRules($component,$view) + protected static function getDefaultAssetRules($component, $view, $inherit = true) { - // Need to find the asset id by the name of the component. - $db = JFactory::getDbo(); - $query = $db->getQuery(true) - ->select($db->quoteName('id')) - ->from($db->quoteName('#__assets')) - ->where($db->quoteName('name') . ' = ' . $db->quote($component)); - $db->setQuery($query); - $db->execute(); - if ($db->loadRowList()) + // if new or inherited + $assetId = 0; + // Only get the actual item rules if not inheriting + if (!$inherit) { - // asset alread set so use saved rules - $assetId = (int) $db->loadResult(); - $result = JAccess::getAssetRules($assetId); - if ($result instanceof JAccessRules) + // Need to find the asset id by the name of the component. + $db = JFactory::getDbo(); + $query = $db->getQuery(true) + ->select($db->quoteName('id')) + ->from($db->quoteName('#__assets')) + ->where($db->quoteName('name') . ' = ' . $db->quote($component)); + $db->setQuery($query); + $db->execute(); + // check that there is a value + if ($db->getNumRows()) { - $_result = (string) $result; - $_result = json_decode($_result); - foreach ($_result as $name => &$rule) - { - $v = explode('.', $name); - if ($view !== $v[0]) - { - // remove since it is not part of this view - unset($_result->$name); - } - else - { - // clear the value since we inherit - $rule = array(); - } - } - // check if there are any view values remaining - if (count((array)$_result)) - { - $_result = json_encode($_result); - $_result = array($_result); - // Instantiate and return the JAccessRules object for the asset rules. - $rules = new JAccessRules($_result); - - return $rules; - } - return $result; + // asset already set so use saved rules + $assetId = (int) $db->loadResult(); } } - return JAccess::getAssetRules(0); + // get asset rules + $result = JAccess::getAssetRules($assetId); + if ($result instanceof JAccessRules) + { + $_result = (string) $result; + $_result = json_decode($_result); + foreach ($_result as $name => &$rule) + { + $v = explode('.', $name); + if ($view !== $v[0]) + { + // remove since it is not part of this view + unset($_result->$name); + } + elseif ($inherit) + { + // clear the value since we inherit + $rule = array(); + } + } + // check if there are any view values remaining + if (count($_result)) + { + $_result = json_encode($_result); + $_result = array($_result); + // Instantiate and return the JAccessRules object for the asset rules. + $rules = new JAccessRules($_result); + // return filtered rules + return $rules; + } + } + return $result; } /** @@ -4291,11 +6145,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Check if have an json string + * Check if have an json string * - * @input string The json string to check + * @input string The json string to check * - * @returns bool true on success + * @returns bool true on success **/ public static function checkJson($string) { @@ -4308,11 +6162,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Check if have an object with a length + * Check if have an object with a length * - * @input object The object to check + * @input object The object to check * - * @returns bool true on success + * @returns bool true on success **/ public static function checkObject($object) { @@ -4324,15 +6178,15 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Check if have an array with a length + * Check if have an array with a length * - * @input array The array to check + * @input array The array to check * - * @returns bool true on success + * @returns bool/int number of items in array on success **/ public static function checkArray($array, $removeEmptyString = false) { - if (isset($array) && is_array($array) && count((array)$array) > 0) + if (isset($array) && is_array($array) && ($nr = count((array)$array)) > 0) { // also make sure the empty strings are removed if ($removeEmptyString) @@ -4346,17 +6200,17 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } return self::checkArray($array, false); } - return true; + return $nr; } return false; } /** - * Check if have a string with a length + * Check if have a string with a length * - * @input string The string to check + * @input string The string to check * - * @returns bool true on success + * @returns bool true on success **/ public static function checkString($string) { @@ -4368,10 +6222,10 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Check if we are connected - * Thanks https://stackoverflow.com/a/4860432/1429677 + * Check if we are connected + * Thanks https://stackoverflow.com/a/4860432/1429677 * - * @returns bool true on success + * @returns bool true on success **/ public static function isConnected() { @@ -4393,11 +6247,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Merge an array of array's + * Merge an array of array's * - * @input array The arrays you would like to merge + * @input array The arrays you would like to merge * - * @returns array on success + * @returns array on success **/ public static function mergeArrays($arrays) { @@ -4423,11 +6277,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Shorten a string + * Shorten a string * - * @input string The you would like to shorten + * @input string The you would like to shorten * - * @returns string on success + * @returns string on success **/ public static function shorten($string, $length = 40, $addTip = true) { @@ -4464,11 +6318,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Making strings safe (various ways) + * Making strings safe (various ways) * - * @input string The you would like to make safe + * @input string The you would like to make safe * - * @returns string on success + * @returns string on success **/ public static function safeString($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true) { @@ -4608,11 +6462,11 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Convert an integer into an English word string - * Thanks to Tom Nicholson + * Convert an integer into an English word string + * Thanks to Tom Nicholson * - * @input an int - * @returns a string + * @input an int + * @returns a string **/ public static function numberToString($x) { @@ -4699,9 +6553,9 @@ $tmp = JHtml::_('bootstrap.addTab', $code . 'Tab', self::randomkey(10), $name); } /** - * Random Key + * Random Key * - * @returns a string + * @returns a string **/ public static function randomkey($size) { diff --git a/site/helpers/route.php b/site/helpers/route.php index 9b2afbe..78b40db 100644 --- a/site/helpers/route.php +++ b/site/helpers/route.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -19,6 +19,49 @@ abstract class MembersmanagerHelperRoute { protected static $lookup; + /** + * @param int The route of the Members + */ + public static function getMembersRoute($id = 0, $catid = 0) + { + if ($id > 0) + { + // Initialize the needel array. + $needles = array( + 'members' => array((int) $id) + ); + // Create the link + $link = 'index.php?option=com_membersmanager&view=members&id='. $id; + } + else + { + // Initialize the needel array. + $needles = array( + 'members' => array() + ); + // Create the link but don't add the id. + $link = 'index.php?option=com_membersmanager&view=members'; + } + if ($catid > 1) + { + $categories = JCategories::getInstance('membersmanager.members'); + $category = $categories->get($catid); + if ($category) + { + $needles['category'] = array_reverse($category->getPath()); + $needles['categories'] = $needles['category']; + $link .= '&catid='.$catid; + } + } + + if ($item = self::_findItem($needles)) + { + $link .= '&Itemid='.$item; + } + + return $link; + } + /** * @param int The route of the Cpanel */ @@ -36,8 +79,10 @@ abstract class MembersmanagerHelperRoute else { // Initialize the needel array. - $needles = array(); - //Create the link but don't add the id. + $needles = array( + 'cpanel' => array() + ); + // Create the link but don't add the id. $link = 'index.php?option=com_membersmanager&view=cpanel'; } if ($catid > 1) @@ -77,8 +122,10 @@ abstract class MembersmanagerHelperRoute else { // Initialize the needel array. - $needles = array(); - //Create the link but don't add the id. + $needles = array( + 'profile' => array() + ); + // Create the link but don't add the id. $link = 'index.php?option=com_membersmanager&view=profile'; } if ($catid > 1) @@ -185,8 +232,8 @@ abstract class MembersmanagerHelperRoute } } return $link; - } - + } + protected static function _findItem($needles = null,$type = null) { $app = JFactory::getApplication(); @@ -234,6 +281,10 @@ abstract class MembersmanagerHelperRoute self::$lookup[$language][$view][$item->query['id']] = $item->id; } } + else + { + self::$lookup[$language][$view][0] = $item->id; + } } } } @@ -244,17 +295,24 @@ abstract class MembersmanagerHelperRoute { if (isset(self::$lookup[$language][$view])) { - foreach ($ids as $id) + if (MembersmanagerHelper::checkArray($ids)) { - if (isset(self::$lookup[$language][$view][(int) $id])) + foreach ($ids as $id) { - return self::$lookup[$language][$view][(int) $id]; + if (isset(self::$lookup[$language][$view][(int) $id])) + { + return self::$lookup[$language][$view][(int) $id]; + } } } + elseif (isset(self::$lookup[$language][$view][0])) + { + return self::$lookup[$language][$view][0]; + } } } } - + if ($type) { // Check if the global menu item has been set. diff --git a/site/language/en-GB/en-GB.com_membersmanager.ini b/site/language/en-GB/en-GB.com_membersmanager.ini index d20077f..d97ea68 100644 --- a/site/language/en-GB/en-GB.com_membersmanager.ini +++ b/site/language/en-GB/en-GB.com_membersmanager.ini @@ -6,6 +6,7 @@ COM_MEMBERSMANAGER_ADD="Add" COM_MEMBERSMANAGER_ADD_ONE_OF_THESE_PLACEHOLDERS_IN_TEXT_FOR_CUSTOM_DOWNLOAD_PLACEMENT="Add one of these placeholders in text for custom download placement" COM_MEMBERSMANAGER_ALLOWED_IMAGE_FORMATS_ARE_NOT_SET_IN_THE_GLOBAL_SETTINGS_PLEASE_NOTIFY_YOUR_SYSTEM_ADMINISTRATOR="Allowed image formats are not set in the global settings, please notify your system administrator." COM_MEMBERSMANAGER_ALL_UNSAVED_WORK_ON_THIS_PAGE_WILL_BE_LOST_ARE_YOU_SURE_YOU_WANT_TO_CONTINUE="All unsaved work on this page will be lost, are you sure you want to continue?" +COM_MEMBERSMANAGER_BACK="Back" COM_MEMBERSMANAGER_BACK_TO_CPANEL="Back to cPanel" COM_MEMBERSMANAGER_BSB_IS_ALREADY_IN_USE_PLEASE_TRY_ANOTHER="%s is already in use, please try another!" COM_MEMBERSMANAGER_CLOSE="Close" @@ -13,22 +14,25 @@ COM_MEMBERSMANAGER_COULD_NOT_UPLOAD_THE_FILE="Could not upload the file!" COM_MEMBERSMANAGER_CPANEL="cPanel" COM_MEMBERSMANAGER_CPANEL_DESC="Control Panel for Members" COM_MEMBERSMANAGER_CREATE="Create" -COM_MEMBERSMANAGER_CREATE_A_REGION="create a region" COM_MEMBERSMANAGER_CREATE_NEW_S="Create New %s" COM_MEMBERSMANAGER_DOES_NOT_HAVE_A_VALID_FILE_TYPE="Does not have a valid file type." COM_MEMBERSMANAGER_DOWNLOAD="Download" COM_MEMBERSMANAGER_EDIT="Edit" COM_MEMBERSMANAGER_EDIT_S="Edit %s" -COM_MEMBERSMANAGER_EXTRA_INFO_AREA="Extra info area" COM_MEMBERSMANAGER_FORMS="Forms" +COM_MEMBERSMANAGER_GO_BACK="go Back" COM_MEMBERSMANAGER_GREAT_SS_IS_AVAILABLE="Great, %s(%s) is available!" +COM_MEMBERSMANAGER_HTWOCURL_NOT_FOUNDHTWOPPLEASE_SETUP_CURL_ON_YOUR_SYSTEM_OR_BMEMBERSMANAGERB_WILL_NOT_FUNCTION_CORRECTLYP="

    Curl Not Found!

    Please setup curl on your system, or membersmanager will not function correctly!

    " +COM_MEMBERSMANAGER_IMAGE="Image" COM_MEMBERSMANAGER_LOADING="Loading" COM_MEMBERSMANAGER_LOGIN_MODULE_POSITION="Login Module Position" COM_MEMBERSMANAGER_MAIN_MEMBER="Main Member" +COM_MEMBERSMANAGER_MAKE_A_SELECTION_TO_CREATE_A_RELATIONSHIP="Make a selection to create a relationship." COM_MEMBERSMANAGER_MEMBER="Member" COM_MEMBERSMANAGER_MEMBERS="Members" COM_MEMBERSMANAGER_MEMBERS_BATCH_OPTIONS="Batch process the selected Members" COM_MEMBERSMANAGER_MEMBERS_BATCH_TIP="All changes will be applied to all selected Members" +COM_MEMBERSMANAGER_MEMBERS_DESC="Any List of Member Details" COM_MEMBERSMANAGER_MEMBERS_N_ITEMS_ARCHIVED="%s Members archived." COM_MEMBERSMANAGER_MEMBERS_N_ITEMS_ARCHIVED_1="%s Member archived." COM_MEMBERSMANAGER_MEMBERS_N_ITEMS_CHECKED_IN_0="No Member successfully checked in." @@ -145,26 +149,27 @@ COM_MEMBERSMANAGER_MEMBER_VERSION_DESC="A count of the number of times this Memb COM_MEMBERSMANAGER_MEMBER_VERSION_LABEL="Revision" COM_MEMBERSMANAGER_MEMBER_WAS_CREATED_SUCCESSFULLY_AND_THE_LOGIN_DETAILS_WAS_EMAILED_TO_THE_MEMBER="Member was created successfully, and the login details was emailed to the member." COM_MEMBERSMANAGER_MEMBER_WAS_NOT_ADDED_TO_ANY_GROUPS_PLEASE_INFORM_YOUR_SYSTEM_ADMINISTRATOR="Member was not added to any groups. Please inform your system administrator." -COM_MEMBERSMANAGER_MORE_SOON="More Soon" COM_MEMBERSMANAGER_NEW="New" COM_MEMBERSMANAGER_NOT_AUTHORISED_TO_VIEW_CPANEL="Not authorised to view cpanel!" +COM_MEMBERSMANAGER_NOT_AUTHORISED_TO_VIEW_MEMBERS="Not authorised to view members!" COM_MEMBERSMANAGER_NOT_AUTHORISED_TO_VIEW_PROFILE="Not authorised to view profile!" +COM_MEMBERSMANAGER_NOT_ENOUGH_DATA="Not enough data" COM_MEMBERSMANAGER_NOT_FOUND_OR_ACCESS_DENIED="Not found or access denied!" COM_MEMBERSMANAGER_NO_ACCESS_GRANTED="No Access Granted!" COM_MEMBERSMANAGER_NO_DETAILS_FOUND="No Details Found" COM_MEMBERSMANAGER_NO_IMPORT_FILE_SELECTED="No import file selected." COM_MEMBERSMANAGER_NO_MEMBER_WAS_FOUND="No member was found" -COM_MEMBERSMANAGER_NO_NAME="No Name" -COM_MEMBERSMANAGER_NO_PLACEHOLDERS_WERE_FOUND_PLEASE_TRY_AGAIN_LATER="No placeholders were found, please try again later." COM_MEMBERSMANAGER_NO_PROFILE_FOUND="No Profile Found" COM_MEMBERSMANAGER_NO_REPORTS_FOUND="No reports found" -COM_MEMBERSMANAGER_NO_REPORTS_FOUND_IN_S="No reports found in %s" +COM_MEMBERSMANAGER_NO_S_FOUND="No %s found" +COM_MEMBERSMANAGER_NO_S_FOUND_IN_S="No %s found in %s" COM_MEMBERSMANAGER_NO_TEMPLATE_FOR_BSB_WERE_FOUND="No template for %s were found" COM_MEMBERSMANAGER_OPEN="Open" COM_MEMBERSMANAGER_OPEN_CPANEL="Open cPanel" COM_MEMBERSMANAGER_OPEN_MAIN_MEMBER_PROFILE="Open Main Member Profile" COM_MEMBERSMANAGER_OPEN_PROFILE="Open Profile" COM_MEMBERSMANAGER_OR="or" +COM_MEMBERSMANAGER_PLACEHOLDERS_NOT_FOUND="Placeholders not found" COM_MEMBERSMANAGER_PLEASE_ENABLE_POPUPS_IN_YOUR_BROWSER_FOR_THIS_WEBSITE_TO_PRINT_THESE_DETAILS="Please enable pop-ups in your browser for this website to print these details!" COM_MEMBERSMANAGER_PLEASE_PUBLISH_A_LOGIN_MODULE_TO_THIS_CODESLOGINCODE_POSITION_AND_INSURE_THAT_YOU_TARGET_THESE_PAGES_THIS_IS_POSSIBLE_IF_YOU_ADD_THE_MODULE_TO_ALL_PAGES_SINCE_THIS_MODULE_POSITION_SHOULD_ONLY_BE_AVAILABLE_IN_THIS_COMPONENT="Please publish a login module to this %s-login position, and insure that you target these pages. This is possible if you add the module to all pages, since this module position should only be available in this component." COM_MEMBERSMANAGER_PRINT="Print" @@ -172,26 +177,29 @@ COM_MEMBERSMANAGER_PRINT_CLOSE="Print & Close" COM_MEMBERSMANAGER_PROFILE="Member Profile" COM_MEMBERSMANAGER_PROFILE_DESC="Member Profile" COM_MEMBERSMANAGER_PROPORTIONALLY="proportionally" +COM_MEMBERSMANAGER_RELATIONSHIPS="Relationships" COM_MEMBERSMANAGER_REMOVE="Remove" COM_MEMBERSMANAGER_REPORTS="Reports" COM_MEMBERSMANAGER_SEARCH_MEMBERS_BY_NAME_TOKEN_OR_EMAIL_HERE="Search members by name, token or email here..." -COM_MEMBERSMANAGER_SELECT_A_REGION="select a region" COM_MEMBERSMANAGER_SEND_REPORT="Send Report" COM_MEMBERSMANAGER_S_COULD_NOT_BE_SAVED_PLEASE_TRY_AGAIN_THIS_COULD_BE_DUE_TO_THE_FACT_THIS_THE_MEMBER_ID_WAS_NOT_READY="%s could not be saved, please try again. This could be due to the fact this the member ID was not ready." COM_MEMBERSMANAGER_S_DATA_COULD_NOT_BE_SAVED="%s data could not be saved" COM_MEMBERSMANAGER_S_OPTIONS="%s Options" COM_MEMBERSMANAGER_THERE_HAS_BEEN_AN_ERROR="There has been an error." +COM_MEMBERSMANAGER_THERE_WAS_AN_ERROR_PLEASE_TRY_AGAIN_LATER_IF_THIS_ERROR_CONTINUES_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="There was an error, please try again later. If this error continues, contact your system administrator." COM_MEMBERSMANAGER_THERE_WAS_NO_REPORT_FOUND="There was no report found!" COM_MEMBERSMANAGER_THE_PROFILE_WILL_BE_CROPPED_TO_THIS_SIZE="The profile will be cropped to this size" COM_MEMBERSMANAGER_TIME_STAMP="Time Stamp" COM_MEMBERSMANAGER_VALUE_ALREADY_TAKEN_PLEASE_TRY_AGAIN="Value already taken, please try again." COM_MEMBERSMANAGER_WARNING_IMPORT_FILE_ERROR="Warning, import file error." COM_MEMBERSMANAGER_WARNING_IMPORT_UPLOAD_ERROR="Warning, import upload error." +COM_MEMBERSMANAGER_YOU_CAN_NOT_DELETE_BSB_FIRST_MOVE_ALL_SUB_ACCOUNTS_TO_NEW_MAIN_MEMBER="You can not delete %s, first move all sub account/s to new main member." COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_ADD_DATA_TO_S_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="You do not have permission to add data to %s, please contact your system administrator." COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_S_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="You do not have permission to edit %s, please contact your system administrator." +COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_THIS_MEMBER_RELATIONSHIPS_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="You do not have permission to edit this member relationships, please contact your system administrator." +COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_EDIT_THIS_MEMBER_TYPE_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR="You do not have permission to edit this member type, please contact your system administrator." COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_REMOVE_THIS_FILE="You do not have permission to remove this file." COM_MEMBERSMANAGER_YOU_DO_NOT_HAVE_PERMISSION_TO_UPLOAD_AN="You do not have permission to upload an" -COM_MEMBERSMANAGER_YOU_WILL_BE_REDIRECTED_TO_AN_EDIT_VIEW_YOU_SURE_YOU_WANT_TO_CONTINUE="You will be redirected to an edit view, you sure you want to continue?" COM_MEMBERSMANAGER__HAS_BEEN_CHECKED_OUT_BY_S="% has been checked out by %s" JGLOBAL_FIELD_ID_DESC="Record number in the database." JGLOBAL_FIELD_ID_LABEL="ID" diff --git a/site/layouts/list_name_value.php b/site/layouts/list_name_value.php index 9b6eba9..b7f0d27 100644 --- a/site/layouts/list_name_value.php +++ b/site/layouts/list_name_value.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/layouts/many_list_name_value.php b/site/layouts/many_list_name_value.php index 2af7091..4348558 100644 --- a/site/layouts/many_list_name_value.php +++ b/site/layouts/many_list_name_value.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -12,7 +12,38 @@ // No direct access to this file defined('JPATH_BASE') or die('Restricted access'); - +$ignore = array('id', 'created', 'modified'); ?> - + + + + +
      + + + +
    • + +
    • + + + + + +
    • + +
    • + + + +
    + +
    ... + diff --git a/site/layouts/member/membership_above.php b/site/layouts/member/membership_above.php index 2c4cf6f..465b5d4 100644 --- a/site/layouts/member/membership_above.php +++ b/site/layouts/member/membership_above.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/layouts/member/membership_left.php b/site/layouts/member/membership_left.php index 343768d..6da2add 100644 --- a/site/layouts/member/membership_left.php +++ b/site/layouts/member/membership_left.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/layouts/member/membership_right.php b/site/layouts/member/membership_right.php index d3e9d37..06ff934 100644 --- a/site/layouts/member/membership_right.php +++ b/site/layouts/member/membership_right.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/layouts/member/publishing.php b/site/layouts/member/publishing.php index aeaea28..2778547 100644 --- a/site/layouts/member/publishing.php +++ b/site/layouts/member/publishing.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/layouts/member/publlshing.php b/site/layouts/member/publlshing.php index 666edf5..7a32c45 100644 --- a/site/layouts/member/publlshing.php +++ b/site/layouts/member/publlshing.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/layouts/panelbox.php b/site/layouts/panelbox.php index 38cf28a..3b1481a 100644 --- a/site/layouts/panelbox.php +++ b/site/layouts/panelbox.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/layouts/profile_uikit_three.php b/site/layouts/profile_uikit_three.php index b5e1cd9..1a12a94 100644 --- a/site/layouts/profile_uikit_three.php +++ b/site/layouts/profile_uikit_three.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/layouts/profile_uikit_two.php b/site/layouts/profile_uikit_two.php index 0ce1268..ca7fac6 100644 --- a/site/layouts/profile_uikit_two.php +++ b/site/layouts/profile_uikit_two.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/layouts/profileassessment_uikit_three.php b/site/layouts/profileassessment_uikit_three.php index ea36c9a..bc27e3f 100644 --- a/site/layouts/profileassessment_uikit_three.php +++ b/site/layouts/profileassessment_uikit_three.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -33,12 +33,26 @@ if ($displayData->setAssessment) { foreach ($displayData->assessments[$_name][$_nr] as $_pointer => &$value) { - $value->name = $assess->name; + if (isset($value->name) && MembersmanagerHelper::checkString($value->name)) + { + $value->name = $assess->name . ' - ' . $value->name; + } + else + { + $value->name = $assess->name; + } } } elseif (MembersmanagerHelper::checkObject($displayData->assessments[$_name][$_nr])) { - $displayData->assessments[$_name][$_nr]->name = $assess->name; + if (isset($displayData->assessments[$_name][$_nr]->name) && MembersmanagerHelper::checkString($displayData->assessments[$_name][$_nr]->name)) + { + $displayData->assessments[$_name][$_nr]->name = $assess->name . ' - ' . $displayData->assessments[$_name][$_nr]->name; + } + else + { + $displayData->assessments[$_name][$_nr]->name = $assess->name; + } } } } @@ -47,7 +61,14 @@ if ($displayData->setAssessment) $displayData->assessments[$_name] = MembersmanagerHelper::getAnyFormDetails($displayData->id, 'member', $assessment->element, 'object', 'profile'); if (MembersmanagerHelper::checkObject($displayData->assessments[$_name])) { - $displayData->assessments[$_name]->name = $assessment->name; + if (isset($displayData->assessments[$_name]->name) && MembersmanagerHelper::checkString($displayData->assessments[$_name]->name)) + { + $displayData->assessments[$_name]->name = $assessment->name . ' - ' . $displayData->assessments[$_name]->name; + } + else + { + $displayData->assessments[$_name]->name = $assessment->name; + } } } } @@ -60,51 +81,10 @@ if ($displayData->setAssessment)
    assessmentAvailable))); ?>
    -
    - - - -
    -

    + -
    -
    -
      - assessmentAvailable as $typeAssesmentName => $components) : ?> - -
    • - - -
    • name; ?>
    • - - - id, 'member', 'id', '=', str_replace("com_", "", $components->element))) !== false): ?> - return_path, $components->element)) !== false): ?> -
    • name; ?>
    • - - -
    • name; ?>
    • - - - - -
    -
    -
    -
    -
    - -
    .
    -
    -
    -
    + diff --git a/site/layouts/profileassessment_uikit_two.php b/site/layouts/profileassessment_uikit_two.php index dedbc9f..ac15b5d 100644 --- a/site/layouts/profileassessment_uikit_two.php +++ b/site/layouts/profileassessment_uikit_two.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -33,12 +33,26 @@ if ($displayData->setAssessment) { foreach ($displayData->assessments[$_name][$_nr] as $_pointer => &$value) { - $value->name = $assess->name; + if (isset($value->name) && MembersmanagerHelper::checkString($value->name)) + { + $value->name = $assess->name . ' - ' . $value->name; + } + else + { + $value->name = $assess->name; + } } } elseif (MembersmanagerHelper::checkObject($displayData->assessments[$_name][$_nr])) { - $displayData->assessments[$_name][$_nr]->name = $assess->name; + if (isset($displayData->assessments[$_name][$_nr]->name) && MembersmanagerHelper::checkString($displayData->assessments[$_name][$_nr]->name)) + { + $displayData->assessments[$_name][$_nr]->name = $assess->name . ' - ' . $displayData->assessments[$_name][$_nr]->name; + } + else + { + $displayData->assessments[$_name][$_nr]->name = $assess->name; + } } } } @@ -47,7 +61,14 @@ if ($displayData->setAssessment) $displayData->assessments[$_name] = MembersmanagerHelper::getAnyFormDetails($displayData->id, 'member', $assessment->element, 'object', 'profile'); if (MembersmanagerHelper::checkObject($displayData->assessments[$_name])) { - $displayData->assessments[$_name]->name = $assessment->name; + if (isset($displayData->assessments[$_name]->name) && MembersmanagerHelper::checkString($displayData->assessments[$_name]->name)) + { + $displayData->assessments[$_name]->name = $assessment->name . ' - ' . $displayData->assessments[$_name]->name; + } + else + { + $displayData->assessments[$_name]->name = $assessment->name; + } } } } @@ -60,51 +81,10 @@ if ($displayData->setAssessment)
    assessmentAvailable))); ?>
    -
    - - - - - - - -
    -

    + -
    -
    -
      - assessmentAvailable as $typeAssesmentName => $components) : ?> - -
    • - - -
    • name; ?>
    • - - - id, 'member', 'id', '=', str_replace("com_", "", $components->element))) !== false): ?> - return_path, $components->element)) !== false): ?> -
    • name; ?>
    • - - -
    • name; ?>
    • - - - - -
    -
    -
    -
    -
    - -
    .
    -
    -
    -
    + diff --git a/site/layouts/profileassessmentselection_uikit_three.php b/site/layouts/profileassessmentselection_uikit_three.php new file mode 100644 index 0000000..7969bcc --- /dev/null +++ b/site/layouts/profileassessmentselection_uikit_three.php @@ -0,0 +1,41 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('JPATH_BASE') or die('Restricted access'); + + + +?> +
    +
    +
      + assessmentAvailable as $typeAssesmentName => $components) : ?> + +
    • + + +
    • name; ?>
    • + + + id, 'member', 'id', '=', str_replace("com_", "", $components->element))) !== false): ?> + return_path, $components->element)) !== false): ?> +
    • name; ?>
    • + + +
    • name; ?>
    • + + + + +
    +
    +
    diff --git a/site/layouts/profileassessmentselection_uikit_two.php b/site/layouts/profileassessmentselection_uikit_two.php new file mode 100644 index 0000000..0c4443f --- /dev/null +++ b/site/layouts/profileassessmentselection_uikit_two.php @@ -0,0 +1,41 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('JPATH_BASE') or die('Restricted access'); + + + +?> +
    +
    +
      + assessmentAvailable as $typeAssesmentName => $components) : ?> + +
    • + + +
    • name; ?>
    • + + + id, 'member', 'id', '=', str_replace("com_", "", $components->element))) !== false): ?> + return_path, $components->element)) !== false): ?> +
    • name; ?>
    • + + +
    • name; ?>
    • + + + + +
    +
    +
    diff --git a/site/layouts/profilebuttons_uikit_three.php b/site/layouts/profilebuttons_uikit_three.php new file mode 100644 index 0000000..08db040 --- /dev/null +++ b/site/layouts/profilebuttons_uikit_three.php @@ -0,0 +1,38 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('JPATH_BASE') or die('Restricted access'); + + + +?> +
    + id)) !== false) : ?> + + + + + + + + + +
    +

    diff --git a/site/layouts/profilebuttons_uikit_two.php b/site/layouts/profilebuttons_uikit_two.php new file mode 100644 index 0000000..120b12a --- /dev/null +++ b/site/layouts/profilebuttons_uikit_two.php @@ -0,0 +1,38 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('JPATH_BASE') or die('Restricted access'); + + + +?> +
    + id)) !== false) : ?> + + + + + + + + + + + + + +
    +

    diff --git a/site/layouts/profiledetails_uikit_three.php b/site/layouts/profiledetails_uikit_three.php index ee23627..36787f9 100644 --- a/site/layouts/profiledetails_uikit_three.php +++ b/site/layouts/profiledetails_uikit_three.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -28,25 +28,43 @@ if ($setInfo) $infoDetails[$_nr] = MembersmanagerHelper::getAnyFormDetails($displayData->id, 'member', $info->element, 'array', 'profile'); } } +// get DB +$db = JFactory::getDBO(); +// set relationships to false +$relationships = false; +// get the types of relationships available to this member +if (($relationshipTypes = MembersmanagerHelper::getRelationshipsByTypes($displayData->type, $db, false, true, false)) !== false) +{ + // load relationships + $relationships = MembersmanagerHelper::getRelationshipsByMember($displayData->id, $db, 'member'); +} ?> - +
    - 3) : ?> + 3) : ?>
        - $infoDetail): ?> - params->membersmanager_relation_type) && 2 == $infoAvailable[$_nr]->params->membersmanager_relation_type): ?> -
      • $infoDetail, 'com' => $infoAvailable[$_nr]->element, 'user' => $displayData->_USER)); ?>
      • - -
      • $infoDetail, 'com' => $infoAvailable[$_nr]->element, 'user' => $displayData->_USER)); ?>
      • - - + + $infoDetail): ?> + params->membersmanager_relation_type) && 2 == $infoAvailable[$_nr]->params->membersmanager_relation_type): ?> +
      • $displayData->id, 'data' => $infoDetail, 'com' => $infoAvailable[$_nr]->element, 'return_path' => $displayData->return_path)); ?>
      • + +
      • $infoDetail, 'com' => $infoAvailable[$_nr]->element, 'user' => $displayData->_USER)); ?>
      • + + + + $displayData->id, 'relationshipTypes' => $relationshipTypes, 'relationships' => $relationships, 'return_path' => $displayData->return_path)); ?>
    diff --git a/site/layouts/profiledetails_uikit_two.php b/site/layouts/profiledetails_uikit_two.php index 99e56ac..2ea3077 100644 --- a/site/layouts/profiledetails_uikit_two.php +++ b/site/layouts/profiledetails_uikit_two.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -28,19 +28,37 @@ if ($setInfo) $infoDetails[$_nr] = MembersmanagerHelper::getAnyFormDetails($displayData->id, 'member', $info->element, 'array', 'profile'); } } +// get DB +$db = JFactory::getDBO(); +// set relationships to false +$relationships = false; +// get the types of relationships available to this member +if (($relationshipTypes = MembersmanagerHelper::getRelationshipsByTypes($displayData->type, $db, false, true, false)) !== false) +{ + // load relationships + $relationships = MembersmanagerHelper::getRelationshipsByMember($displayData->id, $db, 'member'); +} ?> - +
      - $infoDetail): ?> - params->membersmanager_relation_type) && 2 == $infoAvailable[$_nr]->params->membersmanager_relation_type): ?> -
    • $infoDetail, 'com' => $infoAvailable[$_nr]->element, 'user' => $displayData->_USER)); ?>
    • - -
    • $infoDetail, 'com' => $infoAvailable[$_nr]->element, 'user' => $displayData->_USER)); ?>
    • - - + + $infoDetail): ?> + params->membersmanager_relation_type) && 2 == $infoAvailable[$_nr]->params->membersmanager_relation_type): ?> +
    • $displayData->id, 'data' => $infoDetail, 'com' => $infoAvailable[$_nr]->element, 'return_path' => $displayData->return_path)); ?>
    • + +
    • $infoDetail, 'com' => $infoAvailable[$_nr]->element, 'user' => $displayData->_USER)); ?>
    • + + + + $displayData->id, 'relationshipTypes' => $relationshipTypes, 'relationships' => $relationships, 'return_path' => $displayData->return_path)); ?>
    diff --git a/site/layouts/profileextra_uikit_three.php b/site/layouts/profileextra_uikit_three.php index 9a623eb..fed921c 100644 --- a/site/layouts/profileextra_uikit_three.php +++ b/site/layouts/profileextra_uikit_three.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -12,11 +12,84 @@ // No direct access to this file defined('JPATH_BASE') or die('Restricted access'); - + +// set default chart switch to false +$displayData->setCharts = false; +// get names and values if found +if ($displayData->setAssessment) +{ + // get Document + $document = JFactory::getDocument(); + // Chart Target Types + $targets = array(2,3); + // get chart details + $displayData->charts = array(); + $_y = MembersmanagerHelper::safeString($displayData->id); + foreach ($displayData->assessmentAvailable as $_name => $assessment) + { + // set the chart array per/assessment type + $displayData->charts[$_name] = array(); + if (MembersmanagerHelper::checkArray($assessment)) + { + foreach ($assessment as $_nr => $assess) + { + foreach ($targets as $target) + { + if (($carts = MembersmanagerHelper::getAnyAvailableCharts(null, $target, $assess->element)) !== false) + { + foreach ($carts as $key => $cartData) + { + if (($dataTable = MembersmanagerHelper::getAnyMultiChartDataTable($displayData->id, $target, $key, $assess->element)) !== '' + && ($code = MembersmanagerHelper::getAnyChartCode($key . $_y, $dataTable, $cartData['details'], 'profile', $assess->element)) !== false) + { + // load code + $displayData->charts[$_name][] = $code; + // add script to document + $document->addScriptDeclaration($code['script']); + // set loading of charts + $displayData->setCharts = true; + } + } + } + } + } + } + elseif (MembersmanagerHelper::checkObject($assessment) && isset($assessment->element)) + { + foreach ($targets as $target) + { + if (($carts = MembersmanagerHelper::getAnyAvailableCharts(null, $target, $assess->element)) !== false) + { + foreach ($carts as $key => $cartData) + { + if (($dataTable = MembersmanagerHelper::getAnyMultiChartDataTable($displayData->id, $target, $key, $assessment->element)) !== '' + && ($code = MembersmanagerHelper::getAnyChartCode($key . $_y, $dataTable, $cartData['details'], 'profile', $assessment->element)) !== false) + { + // load code + $displayData->charts[$_name][] = $code; + // add script to document + $document->addScriptDeclaration($code['script']); + // set loading of charts + $displayData->setCharts = true; + } + } + } + } + } + } +} ?>
    -
    -

    +setCharts): ?> + charts as $name => $codes): ?> + + + + + +
    +

    .

    +
    diff --git a/site/layouts/profileextra_uikit_two.php b/site/layouts/profileextra_uikit_two.php index cf8252f..e3b9774 100644 --- a/site/layouts/profileextra_uikit_two.php +++ b/site/layouts/profileextra_uikit_two.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -12,11 +12,85 @@ // No direct access to this file defined('JPATH_BASE') or die('Restricted access'); - + +// set default chart switch to false +$displayData->setCharts = false; +// get names and values if found +if ($displayData->setAssessment) +{ + // get Document + $document = JFactory::getDocument(); + // Chart Target Types + $targets = array(2,3); + // get chart details + $displayData->charts = array(); + $_y = MembersmanagerHelper::safeString($displayData->id); + foreach ($displayData->assessmentAvailable as $_name => $assessment) + { + // set the chart array per/assessment type + $displayData->charts[$_name] = array(); + if (MembersmanagerHelper::checkArray($assessment)) + { + foreach ($assessment as $_nr => $assess) + { + foreach ($targets as $target) + { + if (($carts = MembersmanagerHelper::getAnyAvailableCharts(null, $target, $assess->element)) !== false) + { + foreach ($carts as $key => $cartData) + { + if (($dataTable = MembersmanagerHelper::getAnyMultiChartDataTable($displayData->id, $target, $key, $assess->element)) !== '' + && ($code = MembersmanagerHelper::getAnyChartCode($key . $_y, $dataTable, $cartData['details'], 'profile', $assess->element)) !== false) + { + // load code + $displayData->charts[$_name][] = $code; + // add script to document + $document->addScriptDeclaration($code['script']); + // set loading of charts + $displayData->setCharts = true; + } + } + } + } + } + } + elseif (MembersmanagerHelper::checkObject($assessment) && isset($assessment->element)) + { + foreach ($targets as $target) + { + if (($carts = MembersmanagerHelper::getAnyAvailableCharts(null, $target, $assess->element)) !== false) + { + foreach ($carts as $key => $cartData) + { + if (($dataTable = MembersmanagerHelper::getAnyMultiChartDataTable($displayData->id, $target, $key, $assessment->element)) !== '' + && ($code = MembersmanagerHelper::getAnyChartCode($key . $_y, $dataTable, $cartData['details'], 'profile', $assessment->element)) !== false) + { + // load code + $displayData->charts[$_name][] = $code; + // add script to document + $document->addScriptDeclaration($code['script']); + // set loading of charts + $displayData->setCharts = true; + } + } + } + } + } + } +} ?>
    -
    -

    +setCharts): ?> + charts as $name => $codes): ?> + + + + + +
    +

    .

    +
    + diff --git a/site/layouts/profileheader_uikit_three.php b/site/layouts/profileheader_uikit_three.php index fd7a091..9e9093e 100644 --- a/site/layouts/profileheader_uikit_three.php +++ b/site/layouts/profileheader_uikit_three.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -49,7 +49,7 @@ if ((3 == $displayData->account || 4 == $displayData->account) && $displayData-> $addProfileLink = true; } // check if the edit button is to be added -$editButton = MembersmanagerHelper::getEditButton($displayData, 'member', 'members', '&ref=profile&refid=' . $displayData->_REFID, 'com_membersmanager', 'COM_MEMBERSMANAGER_YOU_WILL_BE_REDIRECTED_TO_AN_EDIT_VIEW_YOU_SURE_YOU_WANT_TO_CONTINUE'); +$editButton = MembersmanagerHelper::getEditButton($displayData, 'member', 'members', '&ref=profile&refid=' . $displayData->_REFID, 'com_membersmanager', null); // set the header $header = array(); $header[] = '
    '; diff --git a/site/layouts/profileheader_uikit_two.php b/site/layouts/profileheader_uikit_two.php index e7459dd..bbe9787 100644 --- a/site/layouts/profileheader_uikit_two.php +++ b/site/layouts/profileheader_uikit_two.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -49,7 +49,7 @@ if ((3 == $displayData->account || 4 == $displayData->account) && $displayData-> $addProfileLink = true; } // check if the edit button is to be added -$editButton = MembersmanagerHelper::getEditButton($displayData, 'member', 'members', '&ref=profile&refid=' . $displayData->_REFID, 'com_membersmanager', 'COM_MEMBERSMANAGER_YOU_WILL_BE_REDIRECTED_TO_AN_EDIT_VIEW_YOU_SURE_YOU_WANT_TO_CONTINUE'); +$editButton = MembersmanagerHelper::getEditButton($displayData, 'member', 'members', '&ref=profile&refid=' . $displayData->_REFID, 'com_membersmanager', null); // set the header $header = array(); $header[] = '
    '; diff --git a/site/layouts/profilereports_uikit_three.php b/site/layouts/profilereports_uikit_three.php index 7092762..2a2b9b5 100644 --- a/site/layouts/profilereports_uikit_three.php +++ b/site/layouts/profilereports_uikit_three.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -34,7 +34,7 @@ defined('JPATH_BASE') or die('Restricted access'); 'type' => $displayData->type, 'account' => $displayData->account)); ?> - name; ?> (created); ?>) + name; ?> (created); ?>) id, 'form', 'form', '&return=' . $displayData->return_path, $displayData->assessmentAvailable[$name][$_nr]->element, null); ?> @@ -48,7 +48,7 @@ defined('JPATH_BASE') or die('Restricted access'); 'type' => $displayData->type, 'account' => $displayData->account)); ?> - name; ?> (created); ?>) + name; ?> (created); ?>) id, 'form', 'form', '&return=' . $displayData->return_path, $displayData->assessmentAvailable[$name][$_nr]->element, null); ?> @@ -60,20 +60,20 @@ defined('JPATH_BASE') or die('Restricted access'); // set key $report_key = MembersmanagerHelper::lock(array( 'id' => $assessments->id, - 'element' => $displayData->assessmentAvailable[$name][$_nr]->element, - 'type' => $assessments->type, - 'account' => $assessments->account)); + 'element' => $displayData->assessmentAvailable[$name]->element, + 'type' => $displayData->type, + 'account' => $displayData->account)); ?> - name; ?> (created); ?>) + name; ?> (created); ?>) id, 'form', 'form', '&return=' . $displayData->return_path, $displayData->assessmentAvailable[$name]->element, null); ?> -
  • +
  • - ... + ...
    diff --git a/site/layouts/profilereports_uikit_two.php b/site/layouts/profilereports_uikit_two.php index 90ec24c..a01282d 100644 --- a/site/layouts/profilereports_uikit_two.php +++ b/site/layouts/profilereports_uikit_two.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -34,7 +34,7 @@ defined('JPATH_BASE') or die('Restricted access'); 'type' => $displayData->type, 'account' => $displayData->account)); ?> - name; ?> (created); ?>) + name; ?> (created); ?>) id, 'form', 'form', '&return=' . $displayData->return_path, $displayData->assessmentAvailable[$name][$_nr]->element, null); ?> @@ -48,7 +48,7 @@ defined('JPATH_BASE') or die('Restricted access'); 'type' => $displayData->type, 'account' => $displayData->account)); ?> - name; ?> (created); ?>) + name; ?> (created); ?>) id, 'form', 'form', '&return=' . $displayData->return_path, $displayData->assessmentAvailable[$name][$_nr]->element, null); ?> @@ -60,15 +60,15 @@ defined('JPATH_BASE') or die('Restricted access'); // set key $report_key = MembersmanagerHelper::lock(array( 'id' => $assessments->id, - 'element' => $displayData->assessmentAvailable[$name][$_nr]->element, - 'type' => $assessments->type, - 'account' => $assessments->account)); + 'element' => $displayData->assessmentAvailable[$name]->element, + 'type' => $displayData->type, + 'account' => $displayData->account)); ?> - name; ?> (created); ?>) + name; ?> (created); ?>) id, 'form', 'form', '&return=' . $displayData->return_path, $displayData->assessmentAvailable[$name]->element, null); ?> -
  • +
  • diff --git a/site/layouts/relation_list_name_value.php b/site/layouts/relation_list_name_value.php new file mode 100644 index 0000000..e68b27c --- /dev/null +++ b/site/layouts/relation_list_name_value.php @@ -0,0 +1,33 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('JPATH_BASE') or die('Restricted access'); + + + +?> + +
  • +
      + + $linked_members): ?> + +
    • name; ?>
    • + + +
    • + + + +
    +
  • + diff --git a/site/membersmanager.php b/site/membersmanager.php index a4b88fd..ad02553 100644 --- a/site/membersmanager.php +++ b/site/membersmanager.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/models/ajax.php b/site/models/ajax.php index b1f9b88..879dd4d 100644 --- a/site/models/ajax.php +++ b/site/models/ajax.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -60,6 +60,48 @@ class MembersmanagerModelAjax extends JModelList } return false; } + + // get placeholder header if available + public function getPlaceHolderHeaders($component) + { + if ('com_membersmanager' === $component) + { + return JText::_('COM_MEMBERSMANAGER'); + } + return MembersmanagerHelper::getComponentName($component); + } + + // get chart image link + public function getChartImageLink($image) + { + $view = $this->getViewID(); + // make sure we are in the (allowed) view + if (isset($view['a_view']) && ($view['a_view'] === 'message' || $view['a_view'] === 'profile')) + { + // build image name + $imageName = md5($image . 'jnst_f0r_dumm!es'); + // build image data + $image = explode('base64,', $image); unset($image[0]); $image = str_replace(' ', '+', implode('', $image)); + // validate Base64 + if (($image = MembersmanagerHelper::openValidBase64($image, null, false)) !== false) + { + // validate just png (for now) + $png_binary_check = "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"; + if (substr($image, 0, strlen($png_binary_check)) === $png_binary_check) + { + // build image path + $imagepath = MembersmanagerHelper::getFolderPath('path', 'chartpath') . $imageName . '.png'; + // now write the file if not exists + if (file_exists($imagepath) || MembersmanagerHelper::writeFile($imagepath, $image)) + { + // build and return image link + return array('link' => MembersmanagerHelper::getFolderPath('url', 'chartpath') . $imageName . '.png'); + } + } + } + } + return false; + } // set some buckets protected $target; @@ -607,13 +649,77 @@ class MembersmanagerModelAjax extends JModelList } + /** + * get any placeholder + * + * @param string $getType Name get type + * + * @return string The html string of placeholders + * + */ + public function getAnyPlaceHolders($getType) + { + // check if we should add a header + if (method_exists(__CLASS__, 'getPlaceHolderHeaders') && ($string = $this->getPlaceHolderHeaders($getType)) !== false) + { + $string = JText::_($string) . ' '; + $header = '

    ' . $string . '

    '; + } + else + { + $string = ''; + $header = ''; + } + // get placeholders + if ($placeholders = MembersmanagerHelper::getAnyPlaceHolders($getType)) + { + return '
    ' . $header . '' . + implode(' ', $placeholders) . + '
    '; + } + // not found + return '

    ' . + $string . JText::_('COM_MEMBERSMANAGER_PLACEHOLDERS_NOT_FOUND') . + '!

    ' . + JText::_('COM_MEMBERSMANAGER_THERE_WAS_AN_ERROR_PLEASE_TRY_AGAIN_LATER_IF_THIS_ERROR_CONTINUES_CONTACT_YOUR_SYSTEM_ADMINISTRATOR') . + '
    '; + } + + + /** + * get the placeholder + * + * @param string $getType Name get type + * + * @return string The html string of placeholders + * + */ public function getPlaceHolders($getType) { + // check if we should add a header + if (method_exists(__CLASS__, 'getPlaceHolderHeaders') && ($string = $this->getPlaceHolderHeaders($getType)) !== false) + { + $string = JText::_($string) . ' '; + $header = '

    ' . $string . '

    '; + } + else + { + $string = ''; + $header = ''; + } + // get placeholders if ($placeholders = MembersmanagerHelper::getPlaceHolders($getType)) { - return ''. implode(' ', $placeholders).''; + return '
    ' . $header . '' . + implode(' ', $placeholders) . + '
    '; } - return JText::_('COM_MEMBERSMANAGER_NO_PLACEHOLDERS_WERE_FOUND_PLEASE_TRY_AGAIN_LATER'); + // not found + return '

    ' . + $string . JText::_('COM_MEMBERSMANAGER_PLACEHOLDERS_NOT_FOUND') . + '!

    ' . + JText::_('COM_MEMBERSMANAGER_THERE_WAS_AN_ERROR_PLEASE_TRY_AGAIN_LATER_IF_THIS_ERROR_CONTINUES_CONTACT_YOUR_SYSTEM_ADMINISTRATOR') . + '
    '; } @@ -673,7 +779,7 @@ class MembersmanagerModelAjax extends JModelList $query = $db->getQuery(true); // Select some fields - $query->select($db->quoteName(array('a.id','a.name','a.email','a.token'),array('id','name','email','token'))); + $query->select($db->quoteName(array('a.id','a.name','a.email','a.token','a.type'),array('id','name','email','token','type'))); // From the membersmanager_item table $query->from($db->quoteName('#__membersmanager_member', 'a')); @@ -683,19 +789,8 @@ class MembersmanagerModelAjax extends JModelList $query->join('LEFT', $db->quoteName('#__users', 'g') . ' ON (' . $db->quoteName('a.user') . ' = ' . $db->quoteName('g.id') . ')'); // Filter by published state always (for now) - $query->where('(a.published = 1)'); + $query->where('a.published = 1'); - // get types - $type_access = MembersmanagerHelper::getAccess($user); - // filter to only these groups - if (MembersmanagerHelper::checkArray($type_access)) - { - $query->where('a.type IN (' . implode(',', $type_access) . ')'); - } - else - { - return false; - } // Implement View Level Access if (!$user->authorise('core.options', 'com_membersmanager')) { @@ -722,9 +817,53 @@ class MembersmanagerModelAjax extends JModelList ')'); } $query->order('a.token DESC'); - // set query + // set query (to only get last 10) $db->setQuery($query, 0, 10); - return $db->loadObjectList(); + // get the members + $members = $db->loadObjectList(); + // did we get any + if (MembersmanagerHelper::checkArray($members)) + { + // if system admin, return all found + if ($user->authorise('core.options', 'com_membersmanager')) + { + return $members; + } + // filter by access type + $type_access = MembersmanagerHelper::getAccess($user); + // filter to only these access types + if (MembersmanagerHelper::checkArray($type_access)) + { + // our little function to check if two arrays intersect on values + $intersect = function ($a, $b) { $b = array_flip($b); foreach ($a as $v) { if (isset($b[$v])) return true; } return false; }; + // the new bucket + $member_bucket = array(); + foreach ($members as $member) + { + // convert type json to array + if (MembersmanagerHelper::checkJson($member->type)) + { + $member->type = json_decode($member->type, true); + } + // convert type int to array + if (is_numeric($member->type) && $member->type > 0) + { + $member->type = array($member->type); + } + // now check intersection + if (MembersmanagerHelper::checkArray($member->type) && $intersect($member->type, $type_access)) + { + $member_bucket[] = $member; + } + } + // did we get any + if (MembersmanagerHelper::checkArray($member_bucket)) + { + return $member_bucket; + } + } + } + return false; } // Used in profile diff --git a/site/models/cpanel.php b/site/models/cpanel.php index 1c82224..47c065e 100644 --- a/site/models/cpanel.php +++ b/site/models/cpanel.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -81,8 +81,8 @@ class MembersmanagerModelCpanel extends JModelItem { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_NOT_AUTHORISED_TO_VIEW_CPANEL'), 'error'); - // redirect away to the home page if no access allowed. - $app->redirect(JURI::root()); + // redirect away to the default view if no access allowed. + $app->redirect(JRoute::_('index.php?option=com_membersmanager&view=members')); return false; } $this->userId = $this->user->get('id'); @@ -132,7 +132,7 @@ class MembersmanagerModelCpanel extends JModelItem $app = JFactory::getApplication(); // If no data is found redirect to default page and show warning. $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_NOT_FOUND_OR_ACCESS_DENIED'), 'warning'); - $app->redirect(JURI::root()); + $app->redirect(JRoute::_('index.php?option=com_membersmanager&view=members')); return false; } diff --git a/site/models/forms/member.js b/site/models/forms/member.js index 2caf5fb..0fa6d39 100644 --- a/site/models/forms/member.js +++ b/site/models/forms/member.js @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -278,16 +278,16 @@ function getUserDetails(user){ }); } function getUserDetails_server(user){ - var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.getUserDetails&format=json&vdm="+vastDevMod); + var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.getUserDetails&format=json&raw=true&vdm="+vastDevMod); if(token.length > 0 && user > 0){ var request = 'token='+token+'&user='+user; } return jQuery.ajax({ type: 'GET', url: getUrl, - dataType: 'jsonp', + dataType: 'json', data: request, - jsonp: 'callback' + jsonp: false }); } function setUserDetails(result){ @@ -399,16 +399,16 @@ function removeFile(clearServer, target, flush, type){ } function removeFile_server(currentFileName, target, flush, type){ - var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.removeFile&format=json&vdm="+vastDevMod); + var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.removeFile&format=json&raw=true&vdm="+vastDevMod); if(token.length > 0 && target.length > 0 && type.length > 0){ var request = 'token='+token+'&filename='+currentFileName+'&target='+target+'&flush='+flush+'&type='+type; } return jQuery.ajax({ type: 'GET', url: getUrl, - dataType: 'jsonp', + dataType: 'json', data: request, - jsonp: 'callback' + jsonp: false }); } function isJsonString(str) { @@ -437,16 +437,16 @@ function isEmpty(obj) { function checkUnique_server(value, field){ - var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.checkUnique&format=json&vdm="+vastDevMod); + var getUrl = JRouter("index.php?option=com_membersmanager&task=ajax.checkUnique&format=json&raw=true&vdm="+vastDevMod); if(token.length > 0 && value.length > 0 && field.length > 0){ var request = 'token='+token+'&value='+value+'&field='+field; } return jQuery.ajax({ type: 'GET', url: getUrl, - dataType: 'jsonp', + dataType: 'json', data: request, - jsonp: 'callback' + jsonp: false }); } function checkUnique(value, field, show){ @@ -474,66 +474,4 @@ function checkUnique(value, field, show){ } }); } -} - -// set regions that are on the page -regions = {}; -var region = 0; -jQuery(document).ready(function($) -{ - jQuery("#jform_region option").each(function() - { - var key = jQuery(this).val(); - var text = jQuery(this).text(); - regions[key] = text; - }); - region = jQuery('#jform_region').val(); - getRegion(); -}); - -function getRegion_server(country){ - var getUrl = "index.php?option=com_membersmanager&task=ajax.getRegion&format=json"; - if(token.length > 0 && country > 0){ - var request = 'token='+token+'&country='+country; - } - return jQuery.ajax({ - type: 'GET', - url: getUrl, - dataType: 'jsonp', - data: request, - jsonp: 'callback' - }); -} -function getRegion(){ - jQuery("#loading").show(); - // clear the selection - jQuery('#jform_region').find('option').remove().end(); - jQuery('#jform_region').trigger('liszt:updated'); - // get country value if set - var country = jQuery('#jform_country').val(); - getRegion_server(country).done(function(result) { - setRegion(result); - jQuery("#loading").hide(); - if (typeof regionButton !== 'undefined') { - // ensure button is correct - var region = jQuery('#jform_region').val(); - regionButton(region); - } - }); -} -function setRegion(array){ - if (array) { - jQuery('#jform_region').append(''); - jQuery.each( array, function( i, id ) { - if (id in regions) { - jQuery('#jform_region').append(''); - } - if (id == region) { - jQuery('#jform_region').val(id); - } - }); - } else { - jQuery('#jform_region').append(''); - } - jQuery('#jform_region').trigger('liszt:updated'); } diff --git a/site/models/forms/member.xml b/site/models/forms/member.xml index ad80e13..69997f6 100644 --- a/site/models/forms/member.xml +++ b/site/models/forms/member.xml @@ -263,14 +263,14 @@ message="COM_MEMBERSMANAGER_MEMBER_SURNAME_MESSAGE" hint="COM_MEMBERSMANAGER_MEMBER_SURNAME_HINT" /> - + diff --git a/site/models/member.php b/site/models/member.php index c95c87f..ef1eff6 100644 --- a/site/models/member.php +++ b/site/models/member.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -97,6 +97,14 @@ class MembersmanagerModelMember extends JModelAdmin $item->profile_image = rtrim($medium->decryptString($item->profile_image), "\0"); } + if (!empty($item->type)) + { + // Convert the type field to an array. + $type = new Registry; + $type->loadString($item->type); + $item->type = $type->toArray(); + } + if (empty($item->id)) { @@ -245,12 +253,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('name', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('name')) + if (!($val = $form->getValue('name'))) { // Disable fields while saving. $form->setFieldAttribute('name', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('name', 'required', 'false'); + // Make sure + $form->setValue('name', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('name'); } } // Modify the form based on Edit Email access controls. @@ -284,12 +301,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('email', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('email')) + if (!($val = $form->getValue('email'))) { // Disable fields while saving. $form->setFieldAttribute('email', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('email', 'required', 'false'); + // Make sure + $form->setValue('email', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('email'); } } // Modify the form based on Edit Account access controls. @@ -316,12 +342,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('account', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('account')) + if (!($val = $form->getValue('account'))) { // Disable fields while saving. $form->setFieldAttribute('account', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('account', 'required', 'false'); + // Make sure + $form->setValue('account', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('account'); } } // Modify the form based on Edit User access controls. @@ -348,12 +383,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('user', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('user')) + if (!($val = $form->getValue('user'))) { // Disable fields while saving. $form->setFieldAttribute('user', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('user', 'required', 'false'); + // Make sure + $form->setValue('user', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('user'); } } // Modify the form based on Edit Token access controls. @@ -380,12 +424,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('token', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('token')) + if (!($val = $form->getValue('token'))) { // Disable fields while saving. $form->setFieldAttribute('token', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('token', 'required', 'false'); + // Make sure + $form->setValue('token', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('token'); } } // Modify the form based on Edit Profile Image access controls. @@ -419,12 +472,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('profile_image', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('profile_image')) + if (!($val = $form->getValue('profile_image'))) { // Disable fields while saving. $form->setFieldAttribute('profile_image', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('profile_image', 'required', 'false'); + // Make sure + $form->setValue('profile_image', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('profile_image'); } } // Modify the form based on Edit Main Member access controls. @@ -451,12 +513,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('main_member', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('main_member')) + if (!($val = $form->getValue('main_member'))) { // Disable fields while saving. $form->setFieldAttribute('main_member', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('main_member', 'required', 'false'); + // Make sure + $form->setValue('main_member', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('main_member'); } } // Modify the form based on Edit Password Check access controls. @@ -490,12 +561,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('password_check', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('password_check')) + if (!($val = $form->getValue('password_check'))) { // Disable fields while saving. $form->setFieldAttribute('password_check', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('password_check', 'required', 'false'); + // Make sure + $form->setValue('password_check', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('password_check'); } } // Modify the form based on Edit Password access controls. @@ -529,12 +609,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('password', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('password')) + if (!($val = $form->getValue('password'))) { // Disable fields while saving. $form->setFieldAttribute('password', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('password', 'required', 'false'); + // Make sure + $form->setValue('password', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('password'); } } // Modify the form based on Edit Useremail access controls. @@ -568,12 +657,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('useremail', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('useremail')) + if (!($val = $form->getValue('useremail'))) { // Disable fields while saving. $form->setFieldAttribute('useremail', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('useremail', 'required', 'false'); + // Make sure + $form->setValue('useremail', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('useremail'); } } // Modify the form based on Edit Username access controls. @@ -607,12 +705,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('username', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('username')) + if (!($val = $form->getValue('username'))) { // Disable fields while saving. $form->setFieldAttribute('username', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('username', 'required', 'false'); + // Make sure + $form->setValue('username', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('username'); } } // Modify the form based on Edit Surname access controls. @@ -639,12 +746,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('surname', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('surname')) + if (!($val = $form->getValue('surname'))) { // Disable fields while saving. $form->setFieldAttribute('surname', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('surname', 'required', 'false'); + // Make sure + $form->setValue('surname', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('surname'); } } // Modify the form based on Edit Type access controls. @@ -671,12 +787,21 @@ class MembersmanagerModelMember extends JModelAdmin // Make the field hidded. $form->setFieldAttribute('type', 'type', 'hidden'); // If there is no value continue. - if (!$form->getValue('type')) + if (!($val = $form->getValue('type'))) { // Disable fields while saving. $form->setFieldAttribute('type', 'filter', 'unset'); // Disable fields while saving. $form->setFieldAttribute('type', 'required', 'false'); + // Make sure + $form->setValue('type', null, ''); + } + elseif (MembersmanagerHelper::checkArray($val)) + { + // We have to unset then (TODO) + // Hiddend field can not handel array value + // Even if we conver to json we get an error + $form->removeField('type'); } } // Only load these values if no id is found @@ -925,10 +1050,66 @@ class MembersmanagerModelMember extends JModelAdmin * @since 12.2 */ public function delete(&$pks) - { + { + // check if member is still linked to other sub members as a main member + if (MembersmanagerHelper::checkArray($pks)) + { + // get the application object + $app = JFactory::getApplication(); + // now loop the ids + foreach ($pks as $key => $pk) + { + // check if member still have sub accounts linked to it + if (($found = MembersmanagerHelper::getVar('member', $pk, 'main_member', 'id')) !== false) + { + // set the name + $name = MembersmanagerHelper::getMemberName($pk); + // set a message + $app->enqueueMessage(JText::sprintf('COM_MEMBERSMANAGER_YOU_CAN_NOT_DELETE_BSB_FIRST_MOVE_ALL_SUB_ACCOUNTS_TO_NEW_MAIN_MEMBER', $name), 'Error'); + // remove for the list + unset($pks[$key]); + } + } + } if (!parent::delete($pks)) { return false; + } + + // we must also update all linked tables + if (MembersmanagerHelper::checkArray($pks)) + { + $seek = array('Info', 'Assessment'); + foreach ($seek as $area) + { + if (($components = MembersmanagerHelper::{'get' . $area . 'Components'}()) !== false) + { + foreach($components as $_component) + { + $component = str_replace('com_', '', $_component->element); + $Component = MembersmanagerHelper::safeString($component, 'F'); + // get the linked IDs + if (($ids = MembersmanagerHelper::getVars('form', $pks, 'member', 'id', 'IN', $component)) !== false && MembersmanagerHelper::checkArray($ids)) + { + // get the model + $_Model = MembersmanagerHelper::getModel('form', JPATH_ADMINISTRATOR . '/components/' . $_component->element, $Component); + // do we have the model + if ($_Model) + { + // change publish state + $_Model->delete($ids); + } + } + } + } + } + // now loop the ids + foreach ($pks as $key => $pk) + { + // make sure to remove the type_map + MembersmanagerHelper::updateTypes($pk); + // must still do the relationship clearing (TODO) + } } return true; @@ -949,6 +1130,35 @@ class MembersmanagerModelMember extends JModelAdmin if (!parent::publish($pks, $value)) { return false; + } + + // we must also update all linked tables + if (MembersmanagerHelper::checkArray($pks)) + { + $seek = array('Info', 'Assessment'); + foreach ($seek as $area) + { + if (($components = MembersmanagerHelper::{'get' . $area . 'Components'}()) !== false) + { + foreach($components as $_component) + { + $component = str_replace('com_', '', $_component->element); + $Component = MembersmanagerHelper::safeString($component, 'F'); + // get the linked IDs + if (($ids = MembersmanagerHelper::getVars('form', $pks, 'member', 'id', 'IN', $component)) !== false && MembersmanagerHelper::checkArray($ids)) + { + // get the model + $_Model = MembersmanagerHelper::getModel('form', JPATH_ADMINISTRATOR . '/components/' . $_component->element, $Component); + // do we have the model + if ($_Model) + { + // change publish state + $_Model->publish($ids, $value); + } + } + } + } + } } return true; @@ -1325,16 +1535,39 @@ class MembersmanagerModelMember extends JModelAdmin $data['metadata'] = (string) $metadata; } + // get user object + $user = JFactory::getUser(); + // set ID + $id = (isset($data['id']) && $data['id'] > 0) ? $data['id'] : false; + // little function to check user access + $checkUserAccess = function ($permission) use($user, $id) { + return (($id && $user->authorise('member.' . $permission, 'com_membersmanager.member.' . (int) $id)) || (!$id && $user->authorise('member.' . $permission, 'com_membersmanager'))); + }; + // make sure these type is set + if ($id && !$checkUserAccess('edit.type')) + { + $data['type'] = MembersmanagerHelper::getVar('member', $id, 'id', 'type'); + } + // make sure these account is set + if ($id && !$checkUserAccess('edit.account')) + { + $data['account'] = MembersmanagerHelper::getVar('member', $id, 'id', 'account'); + } + // get user value if not set (due to permissions) + if ($id && isset($data['account']) && (1 == $data['account'] || 4 == $data['account']) && (!isset($data['user']) || $data['user'] == 0)) + { + $data['user'] = MembersmanagerHelper::getVar('member', $id, 'id', 'user'); + } // check if this is a linked user (MUST STILL DO PERMISSIONS) - if (isset($data['account']) && (1 == $data['account'] || 4 == $data['account'])) + if (isset($data['account']) && (1 == $data['account'] || 4 == $data['account']) && $checkUserAccess('edit.user')) { // get the application object $app = JFactory::getApplication(); // check if member already exist - if (isset($data['id']) && $data['id'] > 0 && isset($data['user']) && $data['user'] > 0) + if ($id && isset($data['user']) && $data['user'] > 0) { // do not allow user link to be changed (should have done this in the controller) - if (($alreadyUser = MembersmanagerHelper::getVar('member', $data['id'], 'id', 'user')) !== false && is_numeric($alreadyUser) && $alreadyUser > 0 && $alreadyUser != $data['user']) + if (($alreadyUser = MembersmanagerHelper::getVar('member', $id, 'id', 'user')) !== false && is_numeric($alreadyUser) && $alreadyUser > 0 && $alreadyUser != $data['user']) { $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_MEMBER_IS_ALREADY_LINKED_TO_AN_USER_THIS_CAN_NOT_BE_CHANGED_CONTACT_YOUR_SYSTEM_ADMINISTRATOR_IF_YOU_NEED_MORE_HELP'), 'Error'); return false; @@ -1355,27 +1588,17 @@ class MembersmanagerModelMember extends JModelAdmin { // set user ID $bucket['id'] = $data['user']; - // get user exciting groups + // get member user $memberUser = JFactory::getUser($bucket['id']); - $excitingGroups = $memberUser->get('groups'); - $typeGroups = array(); - // set the groups - if (isset($data['type']) && $data['type'] > 0) - { - // get the target groups - $typeGroups = MembersmanagerHelper::getVar('type', $data['type'], 'id', 'groups_target'); - // convert to array - if (MembersmanagerHelper::checkJson($typeGroups)) - { - $typeGroups = (array) json_decode($typeGroups, true); - } - elseif (is_numeric($typeGroups)) - { - $typeGroups = array((int) $typeGroups); - } - } + // get user exciting groups + $bucket['groups'] = $memberUser->get('groups'); + // remove all groups part of members manager + MembersmanagerHelper::removeMemberGroups($bucket['groups']); // load the user groups (TODO) - $bucket['groups'] = MembersmanagerHelper::mergeArrays(array($excitingGroups, $typeGroups)); + if (($typeGroups = MembersmanagerHelper::getMemberGroupsByType($data['type'])) !== false) + { + $bucket['groups'] = MembersmanagerHelper::mergeArrays(array($bucket['groups'], $typeGroups)); + } // set password if (empty($data['password']) || empty($data['password_check'])) { @@ -1413,25 +1636,11 @@ class MembersmanagerModelMember extends JModelAdmin { // make sure to set the user value $data['user'] = $done; - if (isset($data['type']) && $data['type'] > 0) - { - // get the target groups - $_groups = MembersmanagerHelper::getVar('type', $data['type'], 'id', 'groups_target'); - // convert to array - if (MembersmanagerHelper::checkJson($_groups)) - { - $groups = (array) json_decode($_groups, true); - } - elseif (is_numeric($_groups)) - { - $groups = array((int) $_groups); - } - } // check if we have groups - if (isset($groups) && $groups) + if (($typeGroups = MembersmanagerHelper::getMemberGroupsByType($data['type'])) !== false) { // update the user groups - JUserHelper::setUserGroups((int) $done ,(array) $groups); + JUserHelper::setUserGroups((int) $done, (array) $typeGroups); } else { @@ -1450,12 +1659,25 @@ class MembersmanagerModelMember extends JModelAdmin $data['user'] = $didCreate; } } + // check if the user was set + if (isset($data['user']) && $data['user'] > 0) + { + // the login member must always own it self for edit permissions + $data['created_by'] = $data['user']; + } + } + // if a sub account and not login access + if (isset($data['account']) && 3 == $data['account'] && isset($data['main_member']) && $data['main_member'] > 0 + && ($mainMemberUser = MembersmanagerHelper::getVar('member', $data['main_member'], 'id', 'user')) !== false && $mainMemberUser > 0) + { + // the main user must always own it self for edit permissions + $data['created_by'] = $mainMemberUser; } // always clear out password!! unset($data['password']); unset($data['password_check']); // clear out user if error found - if (empty($data['user']) || $data['user'] == 0 || empty($data['account']) || (1 != $data['account'] && 4 != $data['account'])) + if ((empty($data['user']) || $data['user'] == 0 || empty($data['account']) || (1 != $data['account'] && 4 != $data['account'])) && $checkUserAccess('edit.user') && $checkUserAccess('edit.account')) { // if not a linked account, then no user can be set $data['user'] = ''; @@ -1468,7 +1690,7 @@ class MembersmanagerModelMember extends JModelAdmin // get a token $token = call_user_func(function($data) { // get the name of this member - if ((1 == $data['account'] || 4 == $data['account']) && isset($data['user']) && $data['user'] > 0) + if (isset($data['account']) && (1 == $data['account'] || 4 == $data['account']) && isset($data['user']) && $data['user'] > 0) { return JFactory::getUser($data['user'])->name; } @@ -1483,12 +1705,29 @@ class MembersmanagerModelMember extends JModelAdmin // make string safe $data['token'] = MembersmanagerHelper::safeString(trim(implode(' ', $tokenArray), '-'), 'L', '-', false, false); // get unique token - while (!MembersmanagerHelper::checkUnique($data['id'], 'token', $data['token'], 'member')) + while (!MembersmanagerHelper::checkUnique($id, 'token', $data['token'], 'member')) { $data['token'] = JString::increment($data['token'], 'dash'); } } + // Set the type items to data. + if (isset($data['type']) && is_array($data['type'])) + { + $type = new JRegistry; + $type->loadArray($data['type']); + $data['type'] = (string) $type; + } + // Also check permission since the value may be removed due to permissions + // Then we do not want to clear it out, but simple ignore the empty type + elseif (!isset($data['type']) + && JFactory::getUser()->authorise('member.edit.type', 'com_membersmanager') + && JFactory::getUser()->authorise('member.view.type', 'com_membersmanager')) + { + // Set the empty type to data + $data['type'] = ''; + } + // Get the medium encryption key. $mediumkey = MembersmanagerHelper::getCryptKey('medium'); // Get the encryption object diff --git a/site/models/members.php b/site/models/members.php new file mode 100644 index 0000000..d245a82 --- /dev/null +++ b/site/models/members.php @@ -0,0 +1,247 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +/** + * Membersmanager Model for Members + */ +class MembersmanagerModelMembers extends JModelList +{ + /** + * Model user data. + * + * @var strings + */ + protected $user; + protected $userId; + protected $guest; + protected $groups; + protected $levels; + protected $app; + protected $input; + protected $uikitComp; + + /** + * Method to build an SQL query to load the list data. + * + * @return string An SQL query + */ + protected function getListQuery() + { + // Get the current user for authorisation checks + $this->user = JFactory::getUser(); + $this->userId = $this->user->get('id'); + $this->guest = $this->user->get('guest'); + $this->groups = $this->user->get('groups'); + $this->authorisedGroups = $this->user->getAuthorisedGroups(); + $this->levels = $this->user->getAuthorisedViewLevels(); + $this->app = JFactory::getApplication(); + $this->input = $this->app->input; + $this->initSet = true; + // Get a db connection. + $db = JFactory::getDbo(); + + // Create a new query object. + $query = $db->getQuery(true); + + // Filtering. + + $params = $this->app->getParams(); + // get the targeted types + if (($target_type = $params->get('target_type', false)) === false) + { + return false; + } + + // Get from #__membersmanager_member as a + $query->select($db->quoteName( + array('a.id'), + array('id'))); + $query->from($db->quoteName('#__membersmanager_member', 'a')); + // Check if $params->get('target_account', false) is an array with values. + $array = $params->get('target_account', false); + if (isset($array) && MembersmanagerHelper::checkArray($array)) + { + $query->where('a.account IN (' . implode(',', $array) . ')'); + } + else + { + return false; + } + // Check if MembersmanagerHelper::getMembersByType($target_type, $db) is an array with values. + $array = MembersmanagerHelper::getMembersByType($target_type, $db); + if (isset($array) && MembersmanagerHelper::checkArray($array)) + { + $query->where('a.id IN (' . implode(',', $array) . ')'); + } + else + { + return false; + } + $query->where('a.access IN (' . implode(',', $this->levels) . ')'); + // Get where a.published is 1 + $query->where('a.published = 1'); + $query->order('a.ordering ASC'); + + // return the query object + return $query; + } + + /** + * Method to get an array of data items. + * + * @return mixed An array of data items on success, false on failure. + */ + public function getItems() + { + $user = JFactory::getUser(); + // check if this user has permission to access item + if (!$user->authorise('site.members.access', 'com_membersmanager')) + { + $app = JFactory::getApplication(); + $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_NOT_AUTHORISED_TO_VIEW_MEMBERS'), 'error'); + // redirect away to the home page if no access allowed. + $app->redirect(JURI::root()); + return false; + } + // load parent items + $items = parent::getItems(); + + // Get the global params + $globalParams = JComponentHelper::getParams('com_membersmanager', true); + + // Insure all item fields are adapted where needed. + if (MembersmanagerHelper::checkArray($items)) + { + foreach ($items as $nr => &$item) + { + // Always create a slug for sef URL's + $item->slug = (isset($item->alias) && isset($item->id)) ? $item->id.':'.$item->alias : $item->id; + } + } + + + if (MembersmanagerHelper::checkArray($items)) + { + // get the params from menu settings + $params = $this->app->getParams(); + // get the linked components + $components = $params->get('components', false); + $__components = $params->get('many_components', false); + // loop over the members an load the linked data + foreach ($items as $nr => &$item) + { + // get id + $id = $item->id; + + // get member details + $item = (object) MembersmanagerHelper::getAnyFormDetails($id, 'id', 'com_membersmanager', 'placeholder', 'report', 'id', 'member', 1); + // now load the one to one component data + if (MembersmanagerHelper::checkArray($components)) + { + foreach ($components as $component) + { + // get values + if (($tmp = MembersmanagerHelper::getAnyFormDetails($id, 'member', $component, 'placeholder', 'report', 'member', 'form', 1)) !== false && MembersmanagerHelper::checkArray($tmp)) + { + // add to the item array + foreach ($tmp as $placholder_key => $value) + { + // keep first data set + if (!isset($item->{$placholder_key})) + { + $item->{$placholder_key} = $value; + } + } + // not needed + unset($tmp); + } + } + } + // now load the one to many component data + if (MembersmanagerHelper::checkArray($__components)) + { + // start many data array + foreach ($__components as $_component) + { + // rest buckets + $main_template_0 = ''; + $main_template_1 = ''; + // set component name + $component = $_component['component']; + $qty = (isset($_component['qty']) && is_numeric($_component['qty'])) ? $_component['qty'] : 0; + // check if we have a main template + if (MembersmanagerHelper::checkString($_component['main_template'])) + { + if (strpos($_component['main_template'], '[load_items]') !==false) + { + $_tmp = (array) explode('[load_items]', $_component['main_template']); + $main_template_0 = $_tmp[0]; + if (count($_tmp) >= 2) + { + $main_template_1 = $_tmp[1]; + } + } + else + { + $main_template_0 = $_component['main_template']; + } + } + // get values + if (($_data = MembersmanagerHelper::getAnyFormDetails($id, 'member', $component, 'placeholder', 'report', 'member', 'form', $qty)) !== false && MembersmanagerHelper::checkArray($_data)) + { + // start building this linked component view + $item->{'[' . $_component['placeholder'] . ']'} = $main_template_0; + // check the qty + if (!isset($_data[0])) + { + $item->{'[' . $_component['placeholder'] . ']'} .= MembersmanagerHelper::setDynamicData($_component['item_template'], $_data); + } + else + { + foreach ($_data as $data_placeholders) + { + $item->{'[' . $_component['placeholder'] . ']'} .= MembersmanagerHelper::setDynamicData($_component['item_template'], $data_placeholders); + } + } + $item->{'[' . $_component['placeholder'] . ']'} .= $main_template_1; + } + // remove if not set + if (!isset($item->{'[' . $_component['placeholder'] . ']'})) + { + $item->{'[' . $_component['placeholder'] . ']'} = ''; + } + } + } + } + } + + // return items + return $items; + } + + /** + * Get the uikit needed components + * + * @return mixed An array of objects on success. + * + */ + public function getUikitComp() + { + if (isset($this->uikitComp) && MembersmanagerHelper::checkArray($this->uikitComp)) + { + return $this->uikitComp; + } + return false; + } +} diff --git a/site/models/profile.php b/site/models/profile.php index adb390f..faffc83 100644 --- a/site/models/profile.php +++ b/site/models/profile.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -82,7 +82,7 @@ class MembersmanagerModelProfile extends JModelItem $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_NOT_AUTHORISED_TO_VIEW_PROFILE'), 'error'); // redirect away to the default view if no access allowed. - $app->redirect(JRoute::_('index.php?option=com_membersmanager&view=cpanel')); + $app->redirect(JRoute::_('index.php?option=com_membersmanager&view=members')); return false; } $this->userId = $this->user->get('id'); @@ -156,7 +156,7 @@ class MembersmanagerModelProfile extends JModelItem $app = JFactory::getApplication(); // If no data is found redirect to default page and show warning. $app->enqueueMessage(JText::_('COM_MEMBERSMANAGER_NOT_FOUND_OR_ACCESS_DENIED'), 'warning'); - $app->redirect(JRoute::_('index.php?option=com_membersmanager&view=cpanel')); + $app->redirect(JRoute::_('index.php?option=com_membersmanager&view=members')); return false; } // Load the JEvent Dispatcher @@ -168,6 +168,12 @@ class MembersmanagerModelProfile extends JModelItem // Decode profile_image $data->profile_image = rtrim($medium->decryptString($data->profile_image), "\0"); } + // Check if we can decode type + if (MembersmanagerHelper::checkJson($data->type)) + { + // Decode type + $data->type = json_decode($data->type, true); + } // Check if item has params, or pass whole item. $params = (isset($data->params) && MembersmanagerHelper::checkJson($data->params)) ? json_decode($data->params) : $data; // Make sure the content prepare plugins fire on type_description @@ -228,6 +234,31 @@ class MembersmanagerModelProfile extends JModelItem $item->return_path = urlencode(base64_encode($profile_link)); } } + + if (empty($this->_item[$pk]->id)) + { + $id = 0; + } + else + { + $id = $this->_item[$pk]->id; + } + // set the id and view name to session + if ($vdm = MembersmanagerHelper::get('profile__'.$id)) + { + $this->vastDevMod = $vdm; + } + else + { + // set the vast development method key + $this->vastDevMod = MembersmanagerHelper::randomkey(50); + MembersmanagerHelper::set($this->vastDevMod, 'profile__'.$id); + MembersmanagerHelper::set('profile__'.$id, $this->vastDevMod); + // set a return value if found + $jinput = JFactory::getApplication()->input; + $return = $jinput->get('return', null, 'base64'); + MembersmanagerHelper::set($this->vastDevMod . '__return', $return); + } return $this->_item[$pk]; } @@ -288,6 +319,12 @@ class MembersmanagerModelProfile extends JModelItem // Decode profile_image $item->profile_image = rtrim($medium->decryptString($item->profile_image), "\0"); } + // Check if we can decode type + if (MembersmanagerHelper::checkJson($item->type)) + { + // Decode type + $item->type = json_decode($item->type, true); + } } return $items; } @@ -308,5 +345,10 @@ class MembersmanagerModelProfile extends JModelItem return $this->uikitComp; } return false; + } + + public function getVDM() + { + return $this->vastDevMod; } } diff --git a/site/router.php b/site/router.php index ea38c0a..82baf51 100644 --- a/site/router.php +++ b/site/router.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -68,11 +68,11 @@ class MembersmanagerRouter extends JComponentRouterBase return $segments; } - if (isset($view) && isset($query['id']) && ($view === 'member' || $view === 'cpanel' || $view === 'profile')) + if (isset($view) && isset($query['id']) && ($view === 'member' || $view === 'members' || $view === 'cpanel' || $view === 'profile')) { if ($mId != (int) $query['id'] || $mView != $view) { - if (($view === 'member' || $view === 'cpanel' || $view === 'profile')) + if (($view === 'member' || $view === 'members' || $view === 'cpanel' || $view === 'profile')) { $segments[] = $view; $id = explode(':', $query['id']); @@ -124,6 +124,21 @@ class MembersmanagerRouter extends JComponentRouterBase $vars['id'] = (int) $segments[$count-1]; } break; + case 'members': + $vars['view'] = 'members'; + if (is_numeric($segments[$count-1])) + { + $vars['id'] = (int) $segments[$count-1]; + } + elseif ($segments[$count-1]) + { + $id = $this->getVar('member', $segments[$count-1], 'alias', 'id'); + if($id) + { + $vars['id'] = $id; + } + } + break; case 'cpanel': $vars['view'] = 'cpanel'; if (is_numeric($segments[$count-1])) diff --git a/site/views/cpanel/tmpl/default.php b/site/views/cpanel/tmpl/default.php index 617bd90..6399c40 100644 --- a/site/views/cpanel/tmpl/default.php +++ b/site/views/cpanel/tmpl/default.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -34,7 +34,7 @@ defined('_JEXEC') or die('Restricted access');
    diff --git a/site/views/cpanel/tmpl/default_loginmodule.php b/site/views/cpanel/tmpl/default_loginmodule.php index 6bfbb3b..ed61417 100644 --- a/site/views/cpanel/tmpl/default_loginmodule.php +++ b/site/views/cpanel/tmpl/default_loginmodule.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/views/cpanel/view.html.php b/site/views/cpanel/view.html.php index 4c86ab8..d516996 100644 --- a/site/views/cpanel/view.html.php +++ b/site/views/cpanel/view.html.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/views/member/submitbutton.js b/site/views/member/submitbutton.js index 31b8007..0e6cf69 100644 --- a/site/views/member/submitbutton.js +++ b/site/views/member/submitbutton.js @@ -1,7 +1,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved diff --git a/site/views/member/tmpl/edit.php b/site/views/member/tmpl/edit.php index c1cab90..fb96336 100644 --- a/site/views/member/tmpl/edit.php +++ b/site/views/member/tmpl/edit.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -285,11 +285,6 @@ jQuery('#adminForm').on('change', '#jform_account',function (e) jQuery('#error-profile-image-uploader').html(''); -jQuery(document).ready(function(){ - jQuery(window).load(function () { - jQuery("body").css('background', 'transparent'); - }); -}); jQuery('#adminForm').on('change', '#jform_token',function (e) { e.preventDefault(); var tokenValue = jQuery('#jform_token').val(); @@ -302,12 +297,6 @@ jQuery('#adminForm').on('change', '#jform_user',function (e) { // check if this token value is used getUserDetails(userValue); }); -jQuery('#adminForm').on('change', '#contact_country',function (e) { - e.preventDefault(); - getRegion(); -}); -var select_a_region = ''; -var create_a_region = ''; * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -232,14 +232,14 @@ class MembersmanagerViewMember extends JViewLegacy if ($isAdmin || $uikit != 3) { // add JavaScripts - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/uikit' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/uikit' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); } // add JavaScripts - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/accordion' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/tooltip' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/lightbox' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/notify' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); - $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/upload' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/accordion' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/tooltip' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/lightbox' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/notify' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + $this->document->addScript( JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/upload' . $size . '.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); } // Use Uikit Version 3 elseif (3 == $this->uikitVersion && ($isAdmin || $uikit != 2)) diff --git a/site/views/members/index.html b/site/views/members/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/site/views/members/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/site/views/members/tmpl/default.php b/site/views/members/tmpl/default.php new file mode 100644 index 0000000..3d6edd8 --- /dev/null +++ b/site/views/members/tmpl/default.php @@ -0,0 +1,69 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +// the bucket for uikit 2 classes +$this->classes = array(); + +?> +
    + +params->get('members_display_type', false) == 3) : // List ?> + loadTemplate('member_list'); ?> +params->get('members_display_type', false) == 2) : // Table ?> + loadTemplate('member_table'); ?> + + loadTemplate('member_panels'); ?> + + +uikitVersion && MembersmanagerHelper::checkArray($this->classes)) +{ + // load just in case. + jimport('joomla.filesystem.file'); + $size = $this->params->get('uikit_min'); + $style = $this->params->get('uikit_style'); + // loading... + foreach ($this->classes as $class) + { + foreach (MembersmanagerHelper::$uk_components[$class] as $name) + { + // check if the CSS file exists. + if (JFile::exists(JPATH_ROOT.'/media/com_membersmanager/uikit-v2/css/components/'.$name.$style.$size.'.css')) + { + // load the css. + $this->document->addStyleSheet(JURI::root(true) .'/media/com_membersmanager/uikit-v2/css/components/'.$name.$style.$size.'.css', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + } + // check if the JavaScript file exists. + if (JFile::exists(JPATH_ROOT.'/media/com_membersmanager/uikit-v2/js/components/'.$name.$size.'.js')) + { + // load the js. + $this->document->addScript(JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/components/'.$name.$size.'.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('type' => 'text/javascript', 'async' => 'async') : true); + } + } + } +} +?> + +items) && isset($this->pagination) && isset($this->pagination->pagesTotal) && $this->pagination->pagesTotal > 1): ?> + + + + +
    diff --git a/site/views/members/tmpl/default.xml b/site/views/members/tmpl/default.xml new file mode 100644 index 0000000..f8e5fca --- /dev/null +++ b/site/views/members/tmpl/default.xml @@ -0,0 +1,247 @@ + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    \ No newline at end of file diff --git a/site/views/members/tmpl/default_member_list.php b/site/views/members/tmpl/default_member_list.php new file mode 100644 index 0000000..e0cbd1e --- /dev/null +++ b/site/views/members/tmpl/default_member_list.php @@ -0,0 +1,46 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + + +// get templates +$body_template = $this->params->get('list_template', ''); +$item_template = $this->params->get('list_item_template', ''); +// if uikit 2 then we need to load some more components if needed +if (2 == $this->uikitVersion) +{ + $this->classes = MembersmanagerHelper::getUikitComp($body_template, $this->classes); + $this->classes = MembersmanagerHelper::getUikitComp($item_template, $this->classes); +} +// check that it has the [panel_template] placeholder +if (strpos($body_template, '[load_items]') !==false) +{ + $body_template = explode('[load_items]', $body_template); +} +else +{ + // we may need to do some defaults here + $body_template = array(); +} + +?> + + + + +items as $item): ?> + + + + + diff --git a/site/views/members/tmpl/default_member_panels.php b/site/views/members/tmpl/default_member_panels.php new file mode 100644 index 0000000..472539c --- /dev/null +++ b/site/views/members/tmpl/default_member_panels.php @@ -0,0 +1,46 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + + +// get templates +$body_template = $this->params->get('panels_template', ''); +$item_template = $this->params->get('panel_template', ''); +// if uikit 2 then we need to load some more components if needed +if (2 == $this->uikitVersion) +{ + $this->classes = MembersmanagerHelper::getUikitComp($body_template, $this->classes); + $this->classes = MembersmanagerHelper::getUikitComp($item_template, $this->classes); +} +// check that it has the [panel_template] placeholder +if (strpos($body_template, '[load_items]') !==false) +{ + $body_template = explode('[load_items]', $body_template); +} +else +{ + // we may need to do some defaults here + $body_template = array(); +} + +?> + + + + +items as $item): ?> + + + + + diff --git a/site/views/members/tmpl/default_member_table.php b/site/views/members/tmpl/default_member_table.php new file mode 100644 index 0000000..ad9bc31 --- /dev/null +++ b/site/views/members/tmpl/default_member_table.php @@ -0,0 +1,46 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + + +// get templates +$body_template = $this->params->get('table_template', ''); +$item_template = $this->params->get('table_row_template', ''); +// if uikit 2 then we need to load some more components if needed +if (2 == $this->uikitVersion) +{ + $this->classes = MembersmanagerHelper::getUikitComp($body_template, $this->classes); + $this->classes = MembersmanagerHelper::getUikitComp($item_template, $this->classes); +} +// check that it has the [panel_template] placeholder +if (strpos($body_template, '[load_items]') !==false) +{ + $body_template = explode('[load_items]', $body_template); +} +else +{ + // we may need to do some defaults here + $body_template = array(); +} + +?> + + + + +items as $item): ?> + + + + + diff --git a/site/views/members/tmpl/index.html b/site/views/members/tmpl/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/site/views/members/tmpl/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/site/views/members/view.html.php b/site/views/members/view.html.php new file mode 100644 index 0000000..67e148d --- /dev/null +++ b/site/views/members/view.html.php @@ -0,0 +1,153 @@ + + * @github Joomla Members Manager + * @copyright Copyright (C) 2015. All Rights Reserved + * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +/** + * Membersmanager View class for the Members + */ +class MembersmanagerViewMembers extends JViewLegacy +{ + // Overwriting JView display method + function display($tpl = null) + { + // get combined params of both component and menu + $this->app = JFactory::getApplication(); + $this->params = $this->app->getParams(); + $this->menu = $this->app->getMenu()->getActive(); + // get the user object + $this->user = JFactory::getUser(); + // Initialise variables. + $this->items = $this->get('Items'); + $this->pagination = $this->get('Pagination'); + // load the google lib + $this->document->addScript('https://www.gstatic.com/charts/loader.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + // load the chart current + $this->document->addScriptDeclaration("google.charts.load('current');"); + + // Set the toolbar + $this->addToolBar(); + + // set the document + $this->_prepareDocument(); + + // Check for errors. + if (count($errors = $this->get('Errors'))) + { + throw new Exception(implode("\n", $errors), 500); + } + + parent::display($tpl); + } + + /** + * Prepares the document + */ + protected function _prepareDocument() + { + + // always make sure jquery is loaded. + JHtml::_('jquery.framework'); + // Load the header checker class. + require_once( JPATH_COMPONENT_SITE.'/helpers/headercheck.php' ); + // Initialize the header checker. + $HeaderCheck = new membersmanagerHeaderCheck; + + // Load uikit options. + $uikit = $this->params->get('uikit_load'); + // Set script size. + $size = $this->params->get('uikit_min'); + + // Load uikit version. + $this->uikitVersion = $this->params->get('uikit_version', 2); + + // Use Uikit Version 2 + if (2 == $this->uikitVersion) + { + // Set css style. + $style = $this->params->get('uikit_style'); + + // The uikit css. + if ((!$HeaderCheck->css_loaded('uikit.min') || $uikit == 1) && $uikit != 2 && $uikit != 3) + { + $this->document->addStyleSheet(JURI::root(true) .'/media/com_membersmanager/uikit-v2/css/uikit'.$style.$size.'.css', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + } + // The uikit js. + if ((!$HeaderCheck->js_loaded('uikit.min') || $uikit == 1) && $uikit != 2 && $uikit != 3) + { + $this->document->addScript(JURI::root(true) .'/media/com_membersmanager/uikit-v2/js/uikit'.$size.'.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + } + } + // Use Uikit Version 3 + elseif (3 == $this->uikitVersion) + { + // The uikit css. + if ((!$HeaderCheck->css_loaded('uikit.min') || $uikit == 1) && $uikit != 2 && $uikit != 3) + { + $this->document->addStyleSheet(JURI::root(true) .'/media/com_membersmanager/uikit-v3/css/uikit'.$size.'.css', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + } + // The uikit js. + if ((!$HeaderCheck->js_loaded('uikit.min') || $uikit == 1) && $uikit != 2 && $uikit != 3) + { + $this->document->addScript(JURI::root(true) .'/media/com_membersmanager/uikit-v3/js/uikit'.$size.'.js', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); + } + } + // load the meta description + if ($this->params->get('menu-meta_description')) + { + $this->document->setDescription($this->params->get('menu-meta_description')); + } + // load the key words if set + if ($this->params->get('menu-meta_keywords')) + { + $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); + } + // check the robot params + if ($this->params->get('robots')) + { + $this->document->setMetadata('robots', $this->params->get('robots')); + } + // add the document default css file + $this->document->addStyleSheet(JURI::root(true) .'/components/com_membersmanager/assets/css/members.css', (MembersmanagerHelper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); + } + + /** + * Setting the toolbar + */ + protected function addToolBar() + { + // adding the joomla toolbar to the front + JLoader::register('JToolbarHelper', JPATH_ADMINISTRATOR.'/includes/toolbar.php'); + + // set help url for this view if found + $help_url = MembersmanagerHelper::getHelpUrl('members'); + if (MembersmanagerHelper::checkString($help_url)) + { + JToolbarHelper::help('COM_MEMBERSMANAGER_HELP_MANAGER', false, $help_url); + } + // now initiate the toolbar + $this->toolbar = JToolbar::getInstance(); + } + + /** + * Escapes a value for output in a view script. + * + * @param mixed $var The output to escape. + * + * @return mixed The escaped value. + */ + public function escape($var, $sorten = false, $length = 40) + { + // use the helper htmlEscape method instead. + return MembersmanagerHelper::htmlEscape($var, $this->_charset, $sorten, $length); + } +} diff --git a/site/views/profile/tmpl/default.php b/site/views/profile/tmpl/default.php index c8a8bf1..02afe03 100644 --- a/site/views/profile/tmpl/default.php +++ b/site/views/profile/tmpl/default.php @@ -2,7 +2,7 @@ /** * @package Joomla.Members.Manager * - * @created 6th September, 2015 + * @created 6th July, 2018 * @author Llewellyn van der Merwe * @github Joomla Members Manager * @copyright Copyright (C) 2015. All Rights Reserved @@ -13,13 +13,30 @@ defined('_JEXEC') or die('Restricted access'); JHtml::_('bootstrap.modal'); +// check if this was directed here from a list view of member manager +$return_to = $this->app->input->get('return', null, 'base64'); +if (!is_null($return_to) && \JUri::isInternal(base64_decode($return_to))) +{ + $return_to = base64_decode($return_to); +} ?> user->id > 0): ?> - - - + + + + + + + loadTemplate('profiles'); ?>