/** * Load user list. * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $config = KunenaConfig::getInstance(); if ($config->userlist_allowed && JFactory::getUser()->guest) { throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), '401'); } require_once KPATH_SITE . '/models/user.php'; $this->model = new KunenaModelUser(array(), $this->input); $this->model->initialize($this->getOptions(), $this->getOptions()->get('embedded', false)); $this->state = $this->model->getState(); $this->me = KunenaUserHelper::getMyself(); $this->config = KunenaConfig::getInstance(); $start = $this->state->get('list.start'); $limit = $this->state->get('list.limit'); // Get list of super admins to exclude or not in filter by configuration. $filter = JAccess::getUsersByGroup(8); $finder = new KunenaUserFinder(); $finder->filterByConfiguration($filter)->filterByName($this->state->get('list.search')); $this->total = $finder->count(); $this->pagination = new KunenaPagination($this->total, $start, $limit); $alias = 'ku'; $aliasList = array('id', 'name', 'username', 'email', 'block', 'registerDate', 'lastvisitDate'); if (in_array($this->state->get('list.ordering'), $aliasList)) { $alias = 'a'; } $this->users = $finder->order($this->state->get('list.ordering'), $this->state->get('list.direction') == 'asc' ? 1 : -1, $alias)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find(); }
public function members() { // Check for request forgeries. if (!JSession::checkToken('get')) { echo new JResponseJson(null, 'Invalid Token', true); jexit(); } $app = JFactory::getApplication(); $jinput = $app->input; $groups = $jinput->get('groups', null); if ($groups == null) { echo new JResponseJson(null, 'No given group', true); JFactory::getApplication()->close(); } try { //TODO: move this on ImcHelper so as to be used besides json $members = array(); $groupIds = explode('-', $groups); foreach ($groupIds as $groupId) { $membersIds = JAccess::getUsersByGroup($groupId); //getUsersByGroup($groupId, true) recursively foreach ($membersIds as $userId) { $user = JFactory::getUser($userId); array_push($members, array('name' => $user->name, 'email' => $user->email)); } } echo new JResponseJson($members); } catch (Exception $e) { echo new JResponseJson($e); } }
function fetchElement($name, $value, &$node, $control_name) { // Must load admin language files $lang = JFactory::getLanguage(); $lang->load("com_jevents", JPATH_ADMINISTRATOR); $db = JFactory::getDBO(); $class = $node->attributes('class'); if (!$class) { $class = "inputbox"; } //jimport("joomla.html.html.list"); $params = JComponentHelper::getParams("com_jevents"); $db = JFactory::getDBO(); $rules = JAccess::getAssetRules("com_jevents", true); $creatorgroups = $rules->getData(); if (strpos($name, "jevadmin") === 0) { $action = "core.admin"; } else { if (strpos($name, "jeveditor") === 0) { $action = "core.edit"; } else { if (strpos($name, "jevpublisher") === 0) { $action = "core.edit.state"; } else { if (strpos($name, "admin") === 0) { $action = "core.edit.state"; } else { $action = "core.create"; } } } } // need to merge the arrays because of stupid way Joomla checks super user permissions //$creatorgroups = array_merge($creatorgroups["core.admin"]->getData(), $creatorgroups[$action]->getData()); // use union orf arrays sincee getData no longer has string keys in the resultant array //$creatorgroups = $creatorgroups["core.admin"]->getData()+ $creatorgroups["core.create"]->getData(); // use union orf arrays sincee getData no longer has string keys in the resultant array $creatorgroupsdata = $creatorgroups["core.admin"]->getData(); // take the higher permission setting foreach ($creatorgroups[$action]->getData() as $creatorgroup => $permission) { if ($permission) { $creatorgroupsdata[$creatorgroup] = $permission; } } $users = array(0); foreach ($creatorgroupsdata as $creatorgroup => $permission) { if ($permission == 1) { $users = array_merge(JAccess::getUsersByGroup($creatorgroup, true), $users); } } $sql = "SELECT id AS value, name AS text FROM #__users where id IN (" . implode(",", array_values($users)) . ") ORDER BY name asc"; $db->setQuery($sql); $users = $db->loadObjectList(); $users2[] = JHTML::_('select.option', '0', '- ' . JText::_('SELECT_USER') . ' -'); $users2 = array_merge($users2, $users); $users = JHTML::_('select.genericlist', $users2, $control_name . '[' . $name . ']', 'class="' . $class . '" size="1" ', 'value', 'text', $value); return $users; }
function edit($tpl = null) { $document =& JFactory::getDocument(); // this already includes administrator $livesite = JURI::base(); if (JVersion::isCompatible("1.6.0")) { JEVHelper::stylesheet('eventsadmin16.css', 'administrator/components/' . JEV_COM_COMPONENT . '/assets/css/'); } else { $document->addStyleSheet($livesite . 'components/' . JEV_COM_COMPONENT . '/assets/css/eventsadmin.css'); } $document->setTitle(JText::_('JEVENTS') . ' :: ' . JText::_('JEVENTS')); // Set toolbar items for the page JToolBarHelper::title(JText::_('JEV_EDIT_USER'), 'jevents'); JToolBarHelper::save("user.save"); JToolBarHelper::cancel("user.overview"); //JToolBarHelper::help( 'edit.user', true); $option = JRequest::getCmd('option', JEV_COM_COMPONENT); $db =& JFactory::getDBO(); $params =& JComponentHelper::getParams(JEV_COM_COMPONENT); if (JVersion::isCompatible("1.6.0")) { $rules = JAccess::getAssetRules("com_jevents", true); $creatorgroups = $rules->getData(); $creatorgroups = array_merge($creatorgroups["core.admin"]->getData(), $creatorgroups["core.create"]->getData()); $users = array(0); foreach ($creatorgroups as $creatorgroup => $permission) { if ($permission == 1) { $users = array_merge(JAccess::getUsersByGroup($creatorgroup, true), $users); } } $sql = "SELECT * FROM #__users where id IN (" . implode(",", array_values($users)) . ") ORDER BY name asc"; $db->setQuery($sql); $users = $db->loadObjectList(); } else { $minaccess = $params->getValue("jevcreator_level", 19); // get users AUTHORS and above $sql = "SELECT * FROM #__users where gid>=" . $minaccess; $db->setQuery($sql); $users = $db->loadObjectList(); } $userOptions[] = JHTML::_('select.option', '-1', 'Select User'); foreach ($users as $user) { $userOptions[] = JHTML::_('select.option', $user->id, $user->name . " ({$user->username})"); } $jevuser =& $this->get('user'); $userlist = JHTML::_('select.genericlist', $userOptions, 'user_id', 'class="inputbox" size="1" ', 'value', 'text', $jevuser->user_id); JLoader::register('JEventsCategory', JEV_ADMINPATH . "/libraries/categoryClass.php"); $categories = JEventsCategory::categoriesTree(); $lists['categories'] = JHTML::_('select.genericlist', $categories, 'categories[]', 'multiple="multiple" size="15"', 'value', 'text', explode("|", $jevuser->categories)); // get calendars $sql = "SELECT label as text, ics_id as value FROM #__jevents_icsfile where icaltype=2"; $db->setQuery($sql); $calendars = $db->loadObjectList(); $lists['calendars'] = JHTML::_('select.genericlist', $calendars, 'calendars[]', 'multiple="multiple" size="15"', 'value', 'text', explode("|", $jevuser->calendars)); $this->assignRef('lists', $lists); $this->assignRef("users", $userlist); $this->assignRef('jevuser', $jevuser); JHTML::_('behavior.tooltip'); }
function edit($tpl = null) { $document = JFactory::getDocument(); // this already includes administrator $document->setTitle(JText::_('JEVENTS') . ' :: ' . JText::_('JEVENTS')); // Set toolbar items for the page JToolBarHelper::title(JText::_('JEV_EDIT_USER'), 'jevents'); JToolBarHelper::save("user.save"); JToolBarHelper::cancel("user.overview"); //JToolBarHelper::help( 'edit.user', true); $option = JRequest::getCmd('option', JEV_COM_COMPONENT); $db = JFactory::getDBO(); $params = JComponentHelper::getParams(JEV_COM_COMPONENT); $rules = JAccess::getAssetRules("com_jevents", true); $data = $rules->getData(); $creatorgroups = $data["core.create"]->getData(); foreach ($data["core.admin"]->getData() as $creatorgroup => $permission) { if ($permission == 1) { $creatorgroups[$creatorgroup] = $permission; } } // array_merge does a re-indexing !! //$creatorgroups = array_merge($creatorgroups["core.admin"]->getData(), $creatorgroups["core.create"]->getData()); $users = array(0); foreach ($creatorgroups as $creatorgroup => $permission) { if ($permission == 1) { $users = array_merge(JAccess::getUsersByGroup($creatorgroup, true), $users); } } $sql = "SELECT * FROM #__users where id IN (" . implode(",", array_values($users)) . ") ORDER BY name asc"; $db->setQuery($sql); $users = $db->loadObjectList(); $userOptions[] = JHTML::_('select.option', '-1', JText::_('SELECT_USER')); foreach ($users as $user) { $userOptions[] = JHTML::_('select.option', $user->id, $user->name . " ({$user->username})"); } $jevuser = $this->get('user'); $userlist = JHTML::_('select.genericlist', $userOptions, 'user_id', 'class="inputbox" size="1" ', 'value', 'text', $jevuser->user_id); JLoader::register('JEventsCategory', JEV_ADMINPATH . "/libraries/categoryClass.php"); $categories = JEventsCategory::categoriesTree(); $lists['categories'] = JHTML::_('select.genericlist', $categories, 'categories[]', 'multiple="multiple" size="15"', 'value', 'text', explode("|", $jevuser->categories)); // get calendars $sql = "SELECT label as text, ics_id as value FROM #__jevents_icsfile where icaltype=2"; $db->setQuery($sql); $calendars = $db->loadObjectList(); $lists['calendars'] = JHTML::_('select.genericlist', $calendars, 'calendars[]', 'multiple="multiple" size="15"', 'value', 'text', explode("|", $jevuser->calendars)); $this->assignRef('lists', $lists); $this->assignRef("users", $userlist); $this->assignRef('jevuser', $jevuser); JHTML::_('behavior.tooltip'); if (JevJoomlaVersion::isCompatible("3.0")) { $this->setLayout("edit"); } else { $this->setLayout("edit16"); } }
public function getOptions() { $params = JComponentHelper::getParams("com_jevents"); $db = JFactory::getDBO(); $rules = JAccess::getAssetRules("com_jevents", true); $creatorgroups = $rules->getData(); if (strpos($this->name, "jevadmin") === 0) { $action = "core.admin"; } else { if (strpos($this->name, "jeveditor") === 0) { $action = "core.edit"; } else { if (strpos($this->name, "jevpublisher") === 0) { $action = "core.edit.state"; } else { if (strpos($this->name, "admin") === 0) { $action = "core.edit.state"; } else { $action = "core.create"; } } } } // need to merge the arrays because of stupid way Joomla checks super user permissions //$creatorgroups = array_merge($creatorgroups["core.admin"]->getData(), $creatorgroups[$action]->getData()); // use union orf arrays sincee getData no longer has string keys in the resultant array //$creatorgroups = $creatorgroups["core.admin"]->getData()+ $creatorgroups["core.create"]->getData(); // use union orf arrays sincee getData no longer has string keys in the resultant array $creatorgroupsdata = $creatorgroups["core.admin"]->getData(); // take the higher permission setting foreach ($creatorgroups[$action]->getData() as $creatorgroup => $permission) { if ($permission) { $creatorgroupsdata[$creatorgroup] = $permission; } } $users = array(0); foreach ($creatorgroupsdata as $creatorgroup => $permission) { if ($permission == 1) { $users = array_merge(JAccess::getUsersByGroup($creatorgroup, true), $users); } } $sql = "SELECT id AS value, name AS text , sendEmail FROM #__users where id IN (" . implode(",", array_values($users)) . ") ORDER BY name asc"; $db->setQuery($sql); $users = $db->loadObjectList(); $nulluser = new stdClass(); $nulluser->value = 0; $nulluser->sendEmail = 0; $nulluser->text = JText::_("SELECT_ADMIN"); array_unshift($users, $nulluser); return $users; }
/** * @param EventgalleryLibraryOrder $order * * @return mixed|string */ protected function _sendOrderConfirmationMail($order) { $config = JFactory::getConfig(); $params = JComponentHelper::getParams('com_eventgallery'); $sitename = $config->get('sitename'); $view = $this->getView('Mail', 'html', 'EventgalleryView', array('layout' => 'confirm')); $view->set('order', $order); $view->set('params', $params); $body = $view->loadTemplate(); $mailer = JFactory::getMailer(); $config = JFactory::getConfig(); $subject = JText::sprintf('COM_EVENTGALLERY_CART_CHECKOUT_ORDER_MAIL_CONFIRMATION_SUBJECT', $order->getBillingAddress()->getFirstName() . ' ' . $order->getBillingAddress()->getLastName(), $order->getLineItemsTotalCount(), $order->getLineItemsCount()); $mailer->setSubject("{$sitename} - " . $subject); $mailer->isHTML(true); $mailer->Encoding = 'base64'; $mailer->setBody($body); // Customer Mail $sender = array($config->get('mailfrom'), $config->get('fromname')); $mailer->setSender($sender); $mailer->addRecipient($order->getEMail(), $order->getBillingAddress()->getFirstName() . ' ' . $order->getBillingAddress()->getLastName()); $send = $mailer->Send(); if ($send !== true) { return $mailer->ErrorInfo; } // Admin Mail $mailer->ClearAllRecipients(); $sender = array($order->getEMail(), $order->getBillingAddress()->getFirstName() . ' ' . $order->getBillingAddress()->getLastName()); $mailer->setSender($sender); $userids = JAccess::getUsersByGroup($params->get('admin_usergroup')); foreach ($userids as $userid) { $user = JUser::getInstance($userid); if ($user->sendEmail == 1) { $mailadresses = JMailHelper::cleanAddress($user->email); $mailer->addRecipient($mailadresses); } } $send = $mailer->Send(); if ($send !== true) { return $mailer->ErrorInfo; } return $send; }
public static function getAdminUsers() { if (!is_array(self::$users)) { self::$users = array(); if ($groups = self::getAdminGroups()) { $ids = array(); foreach ($groups as $group) { $ids = array_merge($ids, JAccess::getUsersByGroup($group, true)); } $ids = array_unique($ids); if ($ids) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('u.*')->from('#__users u')->where('u.id IN (' . implode(',', $ids) . ')')->order('u.username ASC'); $db->setQuery($query); self::$users = $db->loadObjectList(); } } } return self::$users; }
function notificationManagerEmail($eventid, $title, $menuid, $u_id) { // Load iCagenda Global Options $iCparams = JComponentHelper::getParams('com_icagenda'); // Load Joomla Config $config = JFactory::getConfig(); // Get the site name if (version_compare(JVERSION, '3.0', 'ge')) { $sitename = $config->get('sitename'); } else { $sitename = $config->getValue('config.sitename'); } // Get Global Joomla Contact Infos if (version_compare(JVERSION, '3.0', 'ge')) { $mailfrom = $config->get('mailfrom'); $fromname = $config->get('fromname'); } else { $mailfrom = $config->getValue('config.mailfrom'); $fromname = $config->getValue('config.fromname'); } $siteURL = JURI::base(); $siteURL = rtrim($siteURL, '/'); //$iCmenuitem=$params->get('iCmenuitem'); $iCmenuitem = false; // Itemid Request (automatic detection of the first iCagenda menu-link, by menuID, and depending of current language) if (version_compare(JVERSION, '3.0', 'ge')) { $langdefault = $config->get('language'); } else { $langdefault = $config->getValue('config.language'); } $langFrontend = $langdefault; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id AS idm')->from('#__menu')->where("(link = 'index.php?option=com_icagenda&view=list') AND (published > 0) AND (language = '{$langFrontend}')"); $db->setQuery($query); $idm = $db->loadResult(); $mItemid = $idm; if ($mItemid == NULL) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id AS noidm')->from('#__menu')->where("(link = 'index.php?option=com_icagenda&view=list') AND (published > 0) AND (language = '*')"); $db->setQuery($query); $noidm = $db->loadResult(); } $nolink = ''; if ($noidm == NULL && $mItemid == NULL) { $nolink = 1; } if (is_numeric($iCmenuitem)) { $lien = $iCmenuitem; } else { if ($mItemid == NULL) { $lien = $noidm; } else { $lien = $mItemid; } } // Set Notification Email to each User groups allowed to approve event submitted $groupid = $iCparams->get('approvalGroups', array("8")); // Load Global Option for Autologin $autologin = $iCparams->get('auto_login', 1); jimport('joomla.access.access'); $adminUsersArray = array(); foreach ($groupid as $gp) { $adminUsers = JAccess::getUsersByGroup($gp, False); // if($adminUsers->block == '0' && empty($adminUsers->activation)){ // if($adminUsers->block == '0'){ $adminUsersArray = array_merge($adminUsersArray, $adminUsers); // } else { // $adminUsersArray = JAccess::getUsersByGroup(8, False); // } } $db = JFactory::getDbo(); $query = $db->getQuery(true); if ($u_id == NULL) { $u_id = 0; } if (!in_array($u_id, $adminUsersArray)) { $matches = implode(',', $adminUsersArray); $query->select('ui.username AS username, ui.email AS email, ui.password AS passw, ui.block AS block, ui.activation AS activation')->from('#__users AS ui')->where("ui.id IN ({$matches}) "); } else { $matches = $u_id; $query->select('ui.username AS username, ui.email AS email, ui.password AS passw, ui.block AS block, ui.activation AS activation')->from('#__users AS ui')->where("ui.id = {$matches} "); } $db->setQuery($query); $managers = $db->loadObjectList(); foreach ($managers as $manager) { if (!in_array($u_id, $adminUsersArray)) { $type = 'approval'; } else { $type = 'confirmation'; } // Create Admin Mailer $adminmailer = JFactory::getMailer(); // Set Sender of Notification Email $adminmailer->setSender(array($mailfrom, $fromname)); $username = $manager->username; $passw = $manager->passw; $email = $manager->email; // Set Recipient of Notification Email $adminrecipient = $email; $adminmailer->addRecipient($adminrecipient); // Set Subject of Admin Notification Email if (!in_array($u_id, $adminUsersArray)) { $adminsubject = JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_SUBJECT', $sitename); } else { $adminsubject = JText::sprintf('COM_ICAGENDA_LEGEND_NEW_EVENT') . ': ' . $title; } $adminmailer->setSubject($adminsubject); // Set Url to preview and checking of event submitted $baseURL = JURI::base(); $subpathURL = JURI::base(true); $baseURL = str_replace('/administrator', '', $baseURL); $subpathURL = str_replace('/administrator', '', $subpathURL); if ($autologin == 1) { $urlpreview = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $eventid . '&Itemid=' . (int) $lien . '&icu=' . $username . '&icp=' . $passw)); $urlcheck = str_replace('&', '&', JRoute::_('administrator/index.php?option=com_icagenda&view=events&Itemid=' . (int) $lien) . '&icu=' . $username . '&icp=' . $passw . '&filter_search=' . $eventid); } else { $urlpreview = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $eventid . '&Itemid=' . (int) $lien)); $urlcheck = str_replace('&', '&', JRoute::_('administrator/index.php?option=com_icagenda&view=events&Itemid=' . (int) $lien) . '&filter_search=' . $eventid); } // $urlpreview = str_replace('&','&', $siteURL.'/index.php?option=com_icagenda&view=list&layout=event&id='.(int)$eventid.'&Itemid='.(int)$lien.'&icu='.$username.'&icp='.$passw); $urlpreviewshort = str_replace('&', '&', $siteURL . '/index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $eventid . '&Itemid=' . (int) $lien); $urlcheckshort = str_replace('&', '&', $siteURL . '/administrator/index.php?option=com_icagenda&view=events'); // Sub Path filtering $subpathURL = ltrim($subpathURL, '/'); // URL Event Preview filtering $urlpreview = ltrim($urlpreview, '/'); if (substr($urlpreview, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlpreview = substr($urlpreview, strlen($subpathURL) + 1); } $urlpreview = rtrim($baseURL, '/') . '/' . ltrim($urlpreview, '/'); // URL Event Check filtering $urlcheck = ltrim($urlcheck, '/'); if (substr($urlcheck, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlcheck = substr($urlcheck, strlen($subpathURL) + 1); } $urlcheck = rtrim($baseURL, '/') . '/' . ltrim($urlcheck, '/'); // $sitename = '<i>'.$sitename.'</i>'; // Set Body of User Notification Email $adminbodycontent = JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_HELLO', $username) . ',<br /><br />'; if ($type == 'approval') { $adminbodycontent .= JText::_('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_NEW_EVENT') . '<br /><br />'; // $adminbodycontent.= 'The following link allows you to preview the event.<br /><br />'; // $adminbodycontent.= 'Preview link: <a href="'.$urlpreview.'">'.$urlpreviewshort.'</a><br /><br />'; // $adminbodycontent.= '[ <a href="'.$urlpreview.'">'.JText::_( 'COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_PREVIEW' ).'</a> ]<br /><br />'; $adminbodycontent .= JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVE_INFO', $sitename) . '<br /><br />'; // $adminbodycontent.= JText::_( 'COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVE_LINK' ).': <a href="'.$urlcheck.'">'.$urlcheckshort.'</a><br /><br />'; $adminbodycontent .= JText::_('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVE_LINK') . ': <a href="' . $urlpreview . '">' . $urlpreviewshort . '</a><br /><br />'; } if ($type == 'confirmation') { $adminbodycontent .= JText::_('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVED_REVIEW') . '<br /><br />'; $adminbodycontent .= '<a href="' . $urlpreview . '">' . $urlpreviewshort . '</a><br /><br />'; } if ($autologin == 1) { $adminbodycontent .= '<hr><small>' . JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_FOOTER', $sitename) . '<small>'; } else { $adminbodycontent .= '<hr><small>' . JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_FOOTER_NO_AUTOLOGIN', $sitename) . '<small>'; } $adminbody = rtrim($adminbodycontent); $adminmailer->isHTML(true); $adminmailer->Encoding = 'base64'; $adminmailer->setBody($adminbody); // Send User Notification Email if (isset($email)) { if ($manager->block == '0' && empty($manager->activation)) { $send = $adminmailer->Send(); } } } }
function getSAUsersIds() { $db = DBHelper::db(); $query = 'SELECT a.`id`, a.`title`'; $query .= ' FROM `#__usergroups` AS a'; $query .= ' LEFT JOIN `#__usergroups` AS b ON a.lft > b.lft AND a.rgt < b.rgt'; $query .= ' GROUP BY a.id'; $query .= ' ORDER BY a.lft ASC'; $db->setQuery($query); $result = $db->loadObjectList(); $saGroup = array(); foreach ($result as $group) { if (JAccess::checkGroup($group->id, 'core.admin')) { $saGroup[] = $group; } } //now we got all the SA groups. Time to get the users $saUsers = array(); if (count($saGroup) > 0) { foreach ($saGroup as $sag) { $userArr = JAccess::getUsersByGroup($sag->id); if (count($userArr) > 0) { foreach ($userArr as $user) { $saUsers[] = $user; } } } } return $saUsers; }
public static function saveEvent($frontend = false) { $database = JFactory::getDBO(); $input = JFactory::getApplication()->input; $caid = $input->getInt('caid', 0); $cancel = $input->getInt('cancel', 0); $deldatei1 = $input->get('deldatei1', 0); $deldatei2 = $input->get('deldatei2', 0); $deldatei3 = $input->get('deldatei3', 0); $deldatei4 = $input->get('deldatei4', 0); $deldatei5 = $input->get('deldatei5', 0); $vorlage = $input->getInt('vorlage', 0, 'string'); $id = $input->getInt('id', 0); $art = $input->getInt('art', 2); $neudatum = MatukioHelperUtilsDate::getCurrentDate(); $recurring = $input->getInt("recurring", 0); $isNew = true; JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); // Zeit formatieren $_begin_date = $input->get('_begin_date', '0000-00-00', 'string'); $_end_date = $input->get('_end_date', '0000-00-00', 'string'); $_booked_date = $input->get('_booked_date', '0000-00-00', 'string'); if ($id > 0) { $kurs = JTable::getInstance('Matukio', 'Table'); $kurs->load($id); $isNew = false; } if ($vorlage > 0) { $kurs = JTable::getInstance('Matukio', 'Table'); $kurs->load($vorlage); } $post = JRequest::get('post'); // Allow HTML for certain fields $post['description'] = JRequest::getVar('description', '', 'post', 'html', JREQUEST_ALLOWHTML); $post['booking_mail'] = JRequest::getVar('booking_mail', '', 'post', 'html', JREQUEST_ALLOWHTML); $post['certificate_code'] = JRequest::getVar('certificate_code', '', 'post', 'html', JREQUEST_ALLOWHTML); $post['shortdesc'] = JRequest::getVar('shortdesc', '', 'post', 'html', JREQUEST_ALLOWHTML); $post['place'] = JRequest::getVar('place', '', 'post', 'html', JREQUEST_ALLOWHTML); $row = JTable::getInstance('Matukio', 'Table'); $row->load($id); if (!$row->bind($post)) { throw new Exception($row->getError(), 42); } // Zuweisung der aktuellen Zeit if ($id == 0) { $row->publishdate = $neudatum; } $row->updated = $neudatum; if ($cancel != $row->cancelled && MatukioHelperSettings::_("notify_participants_cancel", 1)) { $tempmail = 9 + $cancel; $events = MatukioHelperUtilsEvents::getEventsRecurringOnEventId($row->id); foreach ($events as $e) { $database->setQuery("SELECT * FROM #__matukio_bookings WHERE semid='{$e->id}'"); $rows = $database->loadObjectList(); for ($i = 0, $n = count($rows); $i < $n; $i++) { MatukioHelperUtilsEvents::sendBookingConfirmationMail($e, $rows[$i]->id, $tempmail); } } } $row->cancelled = $cancel; $row->catid = $caid; // Zuweisung der Startzeit $row->begin = JFactory::getDate($_begin_date, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false); // Zuweisung der Endzeit $row->end = JFactory::getDate($_end_date, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false); // Zuweisung der Buchungszeit $row->booked = JFactory::getDate($_booked_date, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false); // Neue Daten eintragen $row->description = str_replace('<br>', '<br />', $row->description); $row->description = str_replace('\\"', '"', $row->description); $row->description = str_replace("'", "'", $row->description); $row->fees = str_replace(",", ".", $row->fees); $row->different_fees_override = ""; $different_fees_override = $input->get("different_fees_override", array(), 'Array'); if (count($different_fees_override)) { // Check if element 0 is not empty if (!empty($different_fees_override[0]["title"])) { $row->different_fees_override = json_encode($different_fees_override); } } if ($row->id > 0 or $vorlage > 0) { if ($deldatei1 != 1) { $row->file1 = $kurs->file1; $row->file1code = $kurs->file1code; } if ($deldatei2 != 1) { $row->file2 = $kurs->file2; $row->file2code = $kurs->file2code; } if ($deldatei3 != 1) { $row->file3 = $kurs->file3; $row->file3code = $kurs->file3code; } if ($deldatei4 != 1) { $row->file4 = $kurs->file4; $row->file4code = $kurs->file4code; } if ($deldatei5 != 1) { $row->file5 = $kurs->file5; $row->file5code = $kurs->file5code; } } if ($row->id > 0) { $row->hits = $kurs->hits; } $fileext = explode(' ', strtolower(MatukioHelperSettings::getSettings('file_endings', 'txt zip pdf'))); $filesize = MatukioHelperSettings::getSettings('file_maxsize', 500) * 1024; $fehler = array('', '', '', '', '', '', '', '', '', ''); if (!empty($_FILES['datei1'])) { if (is_file($_FILES['datei1']['tmp_name']) and $_FILES['datei1']['size'] > 0) { if ($_FILES['datei1']['size'] > $filesize) { $fehler[0] = str_replace("SEM_FILE", $_FILES['datei1']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei1ext = array_pop(explode(".", strtolower($_FILES['datei1']['name']))); if (!in_array($datei1ext, $fileext)) { $fehler[1] = str_replace("SEM_FILE", $_FILES['datei1']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[0] == "" and $fehler[1] == "") { if ($deldatei1 != 1) { $row->file1 = $_FILES['datei1']['name']; $row->file1code = base64_encode(file_get_contents($_FILES['datei1']['tmp_name'])); } else { $row->file1 = ""; $row->file1code = ""; } } } } else { // Delete file if ($deldatei1 == 1) { $row->file1 = ""; $row->file1code = ""; } } if (!empty($_FILES['datei2'])) { if (is_file($_FILES['datei2']['tmp_name']) and $_FILES['datei2']['size'] > 0) { if ($_FILES['datei2']['size'] > $filesize) { $fehler[2] = str_replace("SEM_FILE", $_FILES['datei2']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei2ext = array_pop(explode(".", strtolower($_FILES['datei2']['name']))); if (!in_array($datei2ext, $fileext)) { $fehler[3] = str_replace("SEM_FILE", $_FILES['datei2']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[2] == "" and $fehler[3] == "") { $row->file2 = $_FILES['datei2']['name']; $row->file2code = base64_encode(file_get_contents($_FILES['datei2']['tmp_name'])); } } } else { // Delete file if ($deldatei2 == 1) { $row->file2 = ""; $row->file2code = ""; } } if (!empty($_FILES['datei3'])) { if (is_file($_FILES['datei3']['tmp_name']) and $_FILES['datei3']['size'] > 0) { if ($_FILES['datei3']['size'] > $filesize) { $fehler[4] = str_replace("SEM_FILE", $_FILES['datei3']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei3ext = array_pop(explode(".", strtolower($_FILES['datei3']['name']))); if (!in_array($datei3ext, $fileext)) { $fehler[5] = str_replace("SEM_FILE", $_FILES['datei3']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[4] == "" and $fehler[5] == "") { $row->file3 = $_FILES['datei3']['name']; $row->file3code = base64_encode(file_get_contents($_FILES['datei3']['tmp_name'])); } } } else { // Delete file if ($deldatei3 == 1) { $row->file3 = ""; $row->file3code = ""; } } if (!empty($_FILES['datei4'])) { if (is_file($_FILES['datei4']['tmp_name']) and $_FILES['datei4']['size'] > 0) { if ($_FILES['datei4']['size'] > $filesize) { $fehler[6] = str_replace("SEM_FILE", $_FILES['datei4']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei4ext = array_pop(explode(".", strtolower($_FILES['datei4']['name']))); if (!in_array($datei4ext, $fileext)) { $fehler[7] = str_replace("SEM_FILE", $_FILES['datei4']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[6] == "" and $fehler[7] == "") { $row->file4 = $_FILES['datei4']['name']; $row->file4code = base64_encode(file_get_contents($_FILES['datei4']['tmp_name'])); } } } else { // Delete file if ($deldatei4 == 1) { $row->file4 = ""; $row->file4code = ""; } } if (!empty($_FILES['datei5'])) { if (is_file($_FILES['datei5']['tmp_name']) and $_FILES['datei5']['size'] > 0) { if ($_FILES['datei5']['size'] > $filesize) { $fehler[8] = str_replace("SEM_FILE", $_FILES['datei5']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei5ext = array_pop(explode(".", strtolower($_FILES['datei5']['name']))); if (!in_array($datei5ext, $fileext)) { $fehler[9] = str_replace("SEM_FILE", $_FILES['datei5']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[8] == "" and $fehler[9] == "") { $row->file5 = $_FILES['datei5']['name']; $row->file5code = base64_encode(file_get_contents($_FILES['datei5']['tmp_name'])); } } } else { // Delete file if ($deldatei5 == 1) { $row->file5 = ""; $row->file5code = ""; } } // Eingaben ueberpruefen $speichern = true; // Template?? Deprecated if ($art == 3) { if (!MatukioHelperUtilsEvents::checkRequiredFieldValues($row->pattern, 'leer')) { $speichern = false; $fehler[] = JTEXT::_('COM_MATUKIO_YOU_HAVENT_FILLED_OUT_ALL_REQUIRED_FIELDS'); } } else { if (!MatukioHelperUtilsEvents::checkRequiredFieldValues($row->semnum, 'leer') or !MatukioHelperUtilsEvents::checkRequiredFieldValues($row->title, 'leer') or $row->catid == 0 or !MatukioHelperUtilsEvents::checkRequiredFieldValues($row->shortdesc, 'leer')) { $speichern = false; $fehler[] = JTEXT::_('COM_MATUKIO_YOU_HAVENT_FILLED_OUT_ALL_REQUIRED_FIELDS'); } elseif (!MatukioHelperUtilsEvents::checkRequiredFieldValues($row->maxpupil, 'nummer') or !MatukioHelperUtilsEvents::checkRequiredFieldValues($row->nrbooked, 'nummer')) { $speichern = false; $fehler[] = JTEXT::_('COM_MATUKIO_YOU_HAVENT_TYPED_A_NUMBER'); } else { $database->setQuery("SELECT id FROM #__matukio WHERE semnum='{$row->semnum}' AND id!='{$row->id}'"); $rows = $database->loadObjectList(); if (count($rows) > 0) { $speichern = false; $htxt = JTEXT::_('COM_MATUKIO_NOT_UNIQUE_NUMBERS'); if ($id < 1) { $htxt .= " " . JTEXT::_('COM_MATUKIO_EVENT_NOT_STORED'); } $fehler[] = $htxt; } } } // Kurs speichern if ($speichern == true) { // Trigger plugin event $results = $dispatcher->trigger('onBeforeSaveEvent', $row); // Check if we already created recurring events if ($recurring == 1) { $edited = $input->getInt("recurring_edited", 0); if ($row->recurring_created && $edited && $row->id > 0) { // Delete old recurring events $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->delete("#__matukio_recurring")->where("event_id = " . $row->id); $db->setQuery($query); $db->execute(); // Maybe set booking status to deleted too? } else { // Set it to 1 $row->recurring_created = 1; } } if (!$row->check()) { throw new Exception($database->stderr(), 42); } if (!$row->store()) { throw new Exception($database->stderr(), 42); } $row->checkin(); // Trigger plugin event $results = $dispatcher->trigger('onAfterSaveEvent', array('com_matukio.event', &$row, $isNew)); // Create recurring events if ($recurring == 1) { $dates_string = $input->get("recurring_dates", '', 'string'); if (!empty($dates_string)) { $bdate = explode(" ", $row->begin); $bdate = $bdate[0]; // Add begin date (if not already in there) if (strpos($dates_string, $bdate) === false) { $dates_string = $bdate . "," . "{$dates_string}"; } $dates = explode(",", $dates_string); $begin_date = new DateTime($row->begin); $end_date = new DateTime($row->end); $closing_date = new DateTime($row->booked); $diff = $begin_date->diff($end_date); $diff2 = $begin_date->diff($closing_date); $start_time = $begin_date->format("H:i:s"); $year = date('Y'); foreach ($dates as $d) { $rec_start = new DateTime($d . " " . $start_time); $rec_end = clone $rec_start; $rec_end->add($diff); $rec_close = clone $rec_start; $rec_close->add($diff2); $robj = new stdClass(); $robj->event_id = $row->id; $robj->semnum = MatukioHelperUtilsEvents::createNewEventNumber($year); $robj->begin = $rec_start->format("Y-m-d H:i:s"); $robj->end = $rec_end->format("Y-m-d H:i:s"); $robj->booked = $rec_close->format("Y-m-d H:i:s"); $robj->published = 1; $rect = JTable::getInstance('Recurring', 'MatukioTable'); if (!$rect->bind($robj)) { throw new Exception($rect->getError(), 42); } if (!$rect->check()) { throw new Exception($rect->getError(), 42); } if (!$rect->store()) { throw new Exception($rect->getError(), 42); } } } } else { // Delete the current date from recurring table and insert the new one // Delete old recurring events $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select("*")->from("#__matukio_recurring")->where("event_id = " . $row->id); $db->setQuery($query); $recd = $db->loadObjectList(); // Switch from recurring events to none recurring if (count($recd) > 1) { $query = $db->getQuery(true); $query->delete("#__matukio_recurring")->where("event_id = " . $row->id); $db->setQuery($query); $db->execute(); // Insert it ones MatukioHelperRecurring::saveRecurringDateForEvent($row); } elseif (count($recd) == 1) { // Ugly hack $recd = $recd[0]; $rect = JTable::getInstance('Recurring', 'MatukioTable'); $recd->semnum = $row->semnum; $recd->begin = $row->begin; $recd->end = $row->end; $recd->booked = $row->booked; $recd->published = $row->published; // We just update the date if (!$rect->bind($recd)) { throw new Exception($rect->getError(), 42); } if (!$rect->check()) { throw new Exception($rect->getError(), 42); } if (!$rect->store()) { throw new Exception($rect->getError(), 42); } } else { // Insert date into recurring table // Add recurring date MatukioHelperRecurring::saveRecurringDateForEvent($row); } } // Trigger plugin event $results = $dispatcher->trigger('onAfterSaveRecurring', $row); } // Ausgabe der Kurse $fehlerzahl = array_unique($fehler); if (count($fehlerzahl) > 1) { $fehler = array_unique($fehler); if ($fehler[0] == "") { $fehler = array_slice($fehler, 1); } $fehler = implode("<br />", $fehler); JFactory::getApplication()->enqueueMessage($fehler, 'Warning'); } // Notify Admin BCC of event creation if (MatukioHelperSettings::getSettings('sendmail_operator', '') != '' && $isNew && $speichern) { $mailer = JFactory::getMailer(); $mainframe = JFactory::getApplication(); $sender = $mainframe->getCfg('fromname'); $from = $mainframe->getCfg('mailfrom'); $user = JFactory::getUser($row->publisher); $replyname = $user->name; $replyto = $user->email; $subject = JText::_("COM_MATUKIO_NEW_EVENT_CREATED"); $body = JText::_("COM_MATUKIO_NEW_EVENT_CREATED") . "\n\n"; $body .= JText::_("COM_MATUKIO_EVENT_DETAILS") . ":\n\n"; $body .= JText::_("COM_MATUKIO_TITLE") . ":\t\t" . $row->title . "\n"; $body .= JText::_("COM_MATUKIO_RECURRING_SEMNUM") . ":\t\t" . $row->semnum . "\n"; $body .= JText::_("COM_MATUKIO_BEGIN") . ":\t\t" . $row->begin . "\n"; $body .= JText::_("COM_MATUKIO_END") . ":\t\t" . $row->end . "\n"; $body .= JText::_("COM_MATUKIO_EVENT_DEFAULT_PLACE") . ":\t\t" . $row->place . "\n"; $body .= JText::_("COM_MATUKIO_EVENT_DEFAULT_SHORT_DESCRIPTION") . ":\t\t" . $row->shortdesc . "\n"; $body .= JText::_("COM_MATUKIO_PUBLISHER") . ":\t\t" . $user->name . "\n"; $success = $mailer->sendMail($from, $sender, explode(",", MatukioHelperSettings::getSettings('sendmail_operator', '')), $subject, $body, MatukioHelperSettings::getSettings('email_html', 1), null, null, null, $replyto, $replyname); } // Send an notification email to all users with new event details @since 4.3.0 if (MatukioHelperSettings::getSettings('sendmail_newevent', 1) && $isNew && $speichern) { // We send an notification of the new event to all users / user group if (MatukioHelperSettings::_("sendmail_newevent_group", 0)) { // Filter users to the given group if not 0 (all) given jimport('joomla.access.access'); $ids = JAccess::getUsersByGroup(MatukioHelperSettings::_("sendmail_newevent_group", 0)); $query = "SELECT * FROM #__users WHERE block = 0 AND id IN (" . implode(",", $ids) . ")"; $db->setQuery($query); $users = $db->loadObjectList(); } else { // Get all users $query = "SELECT * FROM #__users WHERE block = 0"; $db->setQuery($query); $users = $db->loadObjectList(); } $mailer = JFactory::getMailer(); // Set an empty category here - TODO query it from #__category table $row->category = ""; $tmpl = MatukioHelperTemplates::getEmailBody("mail_newevent", $row, null); // Use HTML or text E-Mail if (MatukioHelperSettings::getSettings('email_html', 1)) { // Start html output $body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n"; $body .= '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n"; $body .= "<head>\n"; $body .= "</head>\n"; $body .= "<body>\n"; $body .= $tmpl->value; $body .= "</body>\n</html>"; } else { $body = $tmpl->value_text; } $subject = $tmpl->subject; $mainframe = JFactory::getApplication(); $sender = $mainframe->getCfg('fromname'); $from = $mainframe->getCfg('mailfrom'); // Loop and sent mail foreach ($users as $u) { $success = $mailer->sendMail($from, $sender, $u->email, $subject, $body, MatukioHelperSettings::getSettings('email_html', 1), null, null, null); $mailer->ClearAllRecipients(); } // E-Mail to Admin / Operator etc. if (MatukioHelperSettings::getSettings('sendmail_operator', '') != "") { $success = $mailer->sendMail($from, $sender, explode(",", MatukioHelperSettings::getSettings('sendmail_operator', '')), $subject, $body, MatukioHelperSettings::getSettings('email_html', 1), null, null, null); $mailer->ClearAllRecipients(); } } $obj = new StdClass(); $obj->id = $row->id; $obj->error = $row->fehler; $obj->error_count = count($fehlerzahl); $obj->saved = $speichern; $obj->event = $row; return $obj; }
/** * * ALL EVENTS DISPLAY * */ public function count_Events() { // Get Params Menu $app = JFactory::getApplication(); $iCmenuParams = $app->getParams(); // Get Data $db = Jfactory::getDbo(); $query = $db->getQuery(true); $query->select('count(e.id) AS nbevents')->from('#__icagenda_events AS e'); // Adding Filter if State Published $where = "(e.state = 1)"; // Adding Filter per Category in Navigation $mcatid = $iCmenuParams->get('mcatid'); if (is_array($mcatid)) { $selcat = implode(', ', $mcatid); if (!in_array('0', $mcatid)) { $where .= " AND (e.catid IN ({$selcat}))"; } } // UTC datetime is converted in joomla config time zone // Get a date object based on UTC. $config = JFactory::getConfig(); if (version_compare(JVERSION, '3.0', 'ge')) { $offset = $config->get('offset'); } else { $offset = $config->getValue('config.offset'); } $joomlaTZ_datetime = JFactory::getDate('now', $offset); $joomlaTZ_date = date('Y-m-d', strtotime($joomlaTZ_datetime)); // Adding Filter per Time in Navigation $filter_time = $iCmenuParams->get('time'); // if($filter_time==1) $where.=' AND e.next >= (CURDATE())'; // if($filter_time==2) $where.=' AND e.next < (CURDATE())'; // if($filter_time==3) $where.=' AND e.next >= (NOW())'; // if($filter_time==4) $where.=' AND (e.next >= (CURDATE()) AND (e.next < (CURDATE() + INTERVAL 1 DAY)))'; if ($filter_time == 1) { $where .= ' AND ' . $db->qn('e.next') . ' >= ' . $db->q($joomlaTZ_date) . ''; } // COM_ICAGENDA_OPTION_TODAY_AND_UPCOMING if ($filter_time == 2) { $where .= ' AND ' . $db->qn('e.next') . ' < ' . $db->q($joomlaTZ_date) . ''; } // COM_ICAGENDA_OPTION_PAST if ($filter_time == 3) { $where .= ' AND ' . $db->qn('e.next') . ' > ' . $db->q($joomlaTZ_datetime) . ''; } // COM_ICAGENDA_OPTION_FUTURE if ($filter_time == 4) { $where .= ' AND (' . $db->qn('e.next') . ' >= ' . $db->q($joomlaTZ_date) . ''; $where .= ' AND (' . $db->qn('e.next') . ' < (' . $db->q($joomlaTZ_date) . ' + INTERVAL 1 DAY)))'; } // Language Control $lang = JFactory::getLanguage(); $langcur = $lang->getTag(); $langcurrent = $langcur; $where .= " AND ((e.language = '{$langcurrent}') OR (e.language = '*') OR (e.language = NULL) OR (e.language = ''))"; // Access Control $user = JFactory::getUser(); $userID = $user->id; $userLevels = $user->getAuthorisedViewLevels(); if (version_compare(JVERSION, '3.0', 'lt')) { $userGroups = $user->getAuthorisedGroups(); } else { $userGroups = $user->groups; } $groupid = JComponentHelper::getParams('com_icagenda')->get('approvalGroups', array("8")); jimport('joomla.access.access'); $adminUsersArray = array(); foreach ($groupid as $gp) { $adminUsers = JAccess::getUsersByGroup($gp, False); $adminUsersArray = array_merge($adminUsersArray, $adminUsers); } // Test if user has Access Permissions if (!in_array('8', $userGroups)) { $useraccess = implode(', ', $userLevels); $where .= ' AND e.access IN (' . $useraccess . ')'; } // Test if user logged-in has Approval Rights if (!in_array($userID, $adminUsersArray) and !in_array('8', $userGroups)) { $where .= ' AND e.approval <> 1'; } else { $where .= ' AND e.approval < 2'; } $query->where($where); $db->setQuery($query); $result = $db->loadObject()->nbevents; return $result; }
function edit($tpl = null) { JEVHelper::script('editical.js', 'components/' . JEV_COM_COMPONENT . '/assets/js/'); $document = JFactory::getDocument(); $document->setTitle(JText::_('EDIT_ICS')); // Set toolbar items for the page JToolBarHelper::title(JText::_('EDIT_ICS'), 'jevents'); //JToolBarHelper::save('icals.save'); $bar = JToolBar::getInstance('toolbar'); if ($this->editItem && isset($this->editItem->ics_id) && $this->editItem->ics_id > 0) { JToolBarHelper::save('icals.savedetails'); } JToolBarHelper::cancel('icals.list'); //JToolBarHelper::help( 'screen.icals.edit', true); $params = JComponentHelper::getParams(JEV_COM_COMPONENT); //$section = $params->get("section",0); $db = JFactory::getDbo(); if ($params->get("authorisedonly", 0)) { // get authorised users $sql = "SELECT u.* FROM #__jev_users as jev LEFT JOIN #__users as u on u.id=jev.user_id where jev.published=1 and jev.cancreate=1"; $db = JFactory::getDBO(); $db->setQuery($sql); $users = $db->loadObjectList(); } else { $rules = JAccess::getAssetRules("com_jevents", true); $creatorgroups = $rules->getData(); // need to merge the arrays because of stupid way Joomla checks super user permissions //$creatorgroups = array_merge($creatorgroups["core.admin"]->getData(), $creatorgroups["core.create"]->getData()); // use union orf arrays sincee getData no longer has string keys in the resultant array //$creatorgroups = $creatorgroups["core.admin"]->getData()+ $creatorgroups["core.create"]->getData(); // use union orf arrays sincee getData no longer has string keys in the resultant array $creatorgroupsdata = $creatorgroups["core.admin"]->getData(); // take the higher permission setting foreach ($creatorgroups["core.create"]->getData() as $creatorgroup => $permission) { if ($permission) { $creatorgroupsdata[$creatorgroup] = $permission; } } $users = array(0); foreach ($creatorgroupsdata as $creatorgroup => $permission) { if ($permission == 1) { $users = array_merge(JAccess::getUsersByGroup($creatorgroup, true), $users); } } $sql = "SELECT * FROM #__users where id IN (" . implode(",", array_values($users)) . ") ORDER BY name asc"; $db->setQuery($sql); $users = $db->loadObjectList(); } $userOptions = array(); foreach ($users as $user) { $userOptions[] = JHTML::_('select.option', $user->id, $user->name . " ({$user->username})"); } $jevuser = JFactory::getUser(); if ($this->editItem && isset($this->editItem->ics_id) && $this->editItem->ics_id > 0 && $this->editItem->created_by > 0) { $created_by = $this->editItem->created_by; } else { $created_by = $jevuser->id; } if (count($userOptions) > 0) { $userlist = JHTML::_('select.genericlist', $userOptions, 'created_by', 'class="inputbox" size="1" ', 'value', 'text', $created_by); } else { $userList = ""; } $this->assignRef("users", $userlist); JHTML::_('behavior.tooltip'); if (JevJoomlaVersion::isCompatible("3.0")) { $this->setLayout("edit"); } else { $this->setLayout("edit16"); } }
public function get_admin_emails($groupId) { if (!$groupId) { return false; } $userids = JAccess::getUsersByGroup($groupId); if (empty($userids)) { return false; } $query = 'select email from #__users where id in (' . implode(',', $userids) . ')'; $this->_db->setQuery($query); $users = $this->_db->loadColumn(); return $users; }
public function onContentAfterSave($context, &$article, $isNew) { $ruleID = $article->id; $ruleState = $article->state; $jgroup_id = $article->jgroup_id; $jsgroup_id = $article->jsgroup_id; //if the sync rule is disabled, take no action and exit if (!$ruleState) { return true; } //if we are not in the right context, exit if (!in_array($context, array('com_jomsocialgroupsync.synchronizationrule', 'com_jomsocialgroupsync.synchronizationrules'))) { return true; } //include Joomla files jimport('joomla.user.helper'); jimport('joomla.access.access'); // Instantiate JomSocial require_once JPATH_ROOT . '/administrator/components/com_community/defines.php'; require_once JPATH_ROOT . '/components/com_community/libraries/core.php'; //update Joomla groups $model = CFactory::getModel('Groups'); $members = $model->getMembers($jsgroup_id); foreach ($members as $member) { //add to Joomla group JUserHelper::addUserToGroup($member->id, $jgroup_id); } // update JomSocial groups $group =& JTable::getInstance('Group', 'CTable'); $data = new stdClass(); $data->approved = 1; $data->permissions = 0; $data->groupid = $jsgroup_id; $jGroupUsers = JAccess::getUsersByGroup($jgroup_id); foreach ($jGroupUsers as $userid) { //add to JomSocial group $data->memberid = $userid; if (!$model->isMember($data->memberid, $data->groupid)) { $group->addMember($data); } } return true; }
function notificationNewEvent($eventid, $title, $description, $venue, $date, $image, $new_event) { // Load iCagenda Global Options $iCparams = JComponentHelper::getParams('com_icagenda'); // Load Joomla Config $config = JFactory::getConfig(); if (version_compare(JVERSION, '3.0', 'ge')) { // Get the site name $sitename = $config->get('sitename'); // Get Global Joomla Contact Infos $mailfrom = $config->get('mailfrom'); $fromname = $config->get('fromname'); // Get default language $langdefault = $config->get('language'); } else { // Get the site name $sitename = $config->getValue('config.sitename'); // Get Global Joomla Contact Infos $mailfrom = $config->getValue('config.mailfrom'); $fromname = $config->getValue('config.fromname'); // Get default language $langdefault = $config->getValue('config.language'); } $siteURL = JURI::base(); $siteURL = rtrim($siteURL, '/'); $iCmenuitem = false; // Itemid Request (automatic detection of the first iCagenda menu-link, by menuID, and depending of current language) $langFrontend = $langdefault; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id AS idm')->from('#__menu')->where("(link = 'index.php?option=com_icagenda&view=list') AND (published > 0) AND (language = '{$langFrontend}')"); $db->setQuery($query); $idm = $db->loadResult(); $mItemid = $idm; if ($mItemid == NULL) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id AS noidm')->from('#__menu')->where("(link = 'index.php?option=com_icagenda&view=list') AND (published > 0) AND (language = '*')"); $db->setQuery($query); $noidm = $db->loadResult(); } $nolink = ''; if ($noidm == NULL && $mItemid == NULL) { $nolink = 1; } if (is_numeric($iCmenuitem)) { $lien = $iCmenuitem; } else { if ($mItemid == NULL) { $lien = $noidm; } else { $lien = $mItemid; } } // Set Notification Email to each User groups allowed to receive a notification email when a new event created $groupid = $iCparams->get('newevent_Groups', array("8")); // Load Global Option for Autologin // $autologin = $iCparams->get('auto_login', 1); jimport('joomla.access.access'); $newevent_Groups_Array = array(); foreach ($groupid as $gp) { $GroupUsers = JAccess::getUsersByGroup($gp, False); $newevent_Groups_Array = array_merge($newevent_Groups_Array, $GroupUsers); } // if ($u_id == NULL) { // $u_id = 0; // } $db = JFactory::getDbo(); $query = $db->getQuery(true); // if (!in_array($u_id, $newevent_Groups_Array)) { // $matches = implode(',', $adminUsersArray); // $query->select('ui.username AS username, ui.email AS email, ui.password AS passw, ui.block AS block, ui.activation AS activation') // ->from('#__users AS ui') // ->where( "ui.id IN ($matches) "); // } else { // $matches = $u_id; $matches = implode(',', $newevent_Groups_Array); $query->select('ui.username AS username, ui.email AS email, ui.password AS passw, ui.block AS block, ui.activation AS activation')->from('#__users AS ui')->where("ui.id IN ({$matches}) "); // ->where( "ui.id = $matches "); // } $db->setQuery($query); $users = $db->loadObjectList(); // Get all users email and group except for senders // $db = JFactory::getDbo(); // $query = $db->getQuery(true) // ->select('email') // ->from('#__users'); // ->where('id != '.(int) $user->get('id')); // if ($grp !== 0) // { // if (empty($to)) // { // $query->where('0'); // } else { // $query->where('id IN (' . implode(',', $to) . ')'); // } // } // if ($disabled == 0){ // $query->where("block = 0"); // } // $db->setQuery($query); // $rows = $db->loadColumn(); foreach ($users as $user) { // Create Notification Mailer $new_mailer = JFactory::getMailer(); // Set Sender of Notification Email $new_mailer->setSender(array($mailfrom, $fromname)); $username = $user->username; $passw = $user->passw; $email = $user->email; // Set Recipient of Notification Email $new_recipient = $email; $new_mailer->addRecipient($email); // Set Subject of New Event Notification Email // $new_subject = JText::sprintf('COM_ICAGENDA_MAIL_NEW_EVENT_SUBJECT', $sitename); $new_subject = 'Nouvel évènement, ' . $sitename; $new_mailer->setSubject($new_subject); // Set Url to preview new event $baseURL = JURI::base(); // $subpathURL = JURI::base(true); $baseURL = str_replace('/administrator', '', $baseURL); // $subpathURL = str_replace('/administrator', '', $subpathURL); $urlpreview = str_replace('&', '&', JRoute::_($baseURL . 'index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $eventid . '&Itemid=' . (int) $lien)); // Sub Path filtering // $subpathURL = ltrim($subpathURL, '/'); // URL Event Preview filtering // $urlpreview = ltrim($urlpreview, '/'); // if(substr($urlpreview,0,strlen($subpathURL)+1) == "$subpathURL/") $urlpreview = substr($urlpreview,strlen($subpathURL)+1); // $urlpreview = rtrim($baseURL,'/').'/'.ltrim($urlpreview,'/'); /** * Set Body of User Notification Email */ // Hello // $new_body_hello = JText::sprintf( 'COM_ICAGENDA_MAIL_NEW_EVENT_BODY_HELLO', $username); $new_body_hello = 'Bonjour,'; $new_bodycontent = $new_body_hello . '<br /><br />'; // Text // $new_body_text = JText::sprintf( 'COM_ICAGENDA_MAIL_NEW_EVENT_BODY_TEXT', $sitename); $new_body_text = $sitename . ' vous propose un nouvel évènement :'; $new_bodycontent .= $new_body_text . '<br /><br />'; // Event Details $new_bodycontent .= $title ? 'Titre: ' . $title . '<br />' : ''; $new_bodycontent .= $description ? 'Description: ' . $description . '<br />' : ''; $new_bodycontent .= $venue ? 'Lieu: ' . $venue . '<br />' : ''; $new_bodycontent .= $date ? 'Date: ' . $date . '<br /><br />' : ''; $new_bodycontent .= $image . '<br /><br />'; // Link to event details view $new_bodycontent .= '<a href="' . $urlpreview . '">' . $urlpreview . '</a><br /><br />'; // Footer $new_body_footer = 'Do not answer to this e-mail notification as it is a generated e-mail. You are receiving this email message because you are registered at ' . $sitename . '.'; $new_bodycontent .= '<hr><small>' . $new_body_footer . '<small>'; // Removes spaces (leading, ending) from Body $new_body = rtrim($new_bodycontent); // Authorizes HTML $new_mailer->isHTML(true); $new_mailer->Encoding = 'base64'; // Set Body $new_mailer->setBody($new_body); // Send User Notification Email if (isset($email)) { if ($user->block == '0' && empty($user->activation)) { $send = $new_mailer->Send(); } } } }
/** * The sql must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * * @param string Target search string * @param string mathcing option, exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category * @param mixed An array if the search it to be restricted to areas, null if search all */ function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $db = JFactory::getDBO(); $app = JFactory::getApplication(); $tag = JFactory::getLanguage()->getTag(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); // If the array is not correct, return it: if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } // Now retrieve the plugin parameters $search_name = $this->params->get('search_name', JText::_('ICAGENDA_PLG_SEARCH_SECTION_EVENTS')); if ($search_name == 'ICAGENDA_PLG_SEARCH_SECTION_EVENTS') { $search_name = 'Events'; } $search_limit = $this->params->get('search_limit', '50'); $search_target = $this->params->get('search_target', '0'); // Use the PHP function trim to delete spaces in front of or at the back of the searching terms $text = trim($text); // Return Array when nothing was filled in. if ($text == '') { return array(); } // Database part. $wheres = array(); switch ($phrase) { // Search exact case 'exact': $text = $db->Quote('%' . $db->escape($text, true) . '%', false); $wheres2 = array(); $wheres2[] = 'LOWER(a.title) LIKE ' . $text; $wheres2[] = 'LOWER(a.desc) LIKE ' . $text; $wheres2[] = 'LOWER(a.place) LIKE ' . $text; $wheres2[] = 'LOWER(a.city) LIKE ' . $text; $wheres2[] = 'LOWER(a.country) LIKE ' . $text; $wheres2[] = 'LOWER(a.address) LIKE ' . $text; $wheres2[] = 'LOWER(c.title) LIKE ' . $text; $where = '(' . implode(') OR (', $wheres2) . ')'; break; // Search all or any // Search all or any case 'all': case 'any': // Set default // Set default default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->Quote('%' . $db->escape($word, true) . '%', false); $wheres2 = array(); $wheres2[] = 'LOWER(a.title) LIKE ' . $word; $wheres2[] = 'LOWER(a.desc) LIKE ' . $word; $wheres2[] = 'LOWER(a.place) LIKE ' . $word; $wheres2[] = 'LOWER(a.city) LIKE ' . $word; $wheres2[] = 'LOWER(a.country) LIKE ' . $word; $wheres2[] = 'LOWER(a.address) LIKE ' . $word; $wheres2[] = 'LOWER(c.title) LIKE ' . $word; $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } // Ordering of the results switch ($ordering) { //Alphabetic, ascending case 'alpha': $order = 'a.title ASC'; break; // Oldest first // Oldest first case 'oldest': $order = 'a.next ASC'; break; // Popular first // Popular first case 'popular': // Newest first // Newest first case 'newest': $order = 'a.next DESC'; break; // Category // Category case 'category': $order = 'c.title ASC'; break; // Default setting: alphabetic, ascending // Default setting: alphabetic, ascending default: $order = 'a.title ASC'; } // Section $section = $search_name; // Request Itemid $query = $db->getQuery(true); $query->select('m.id AS idm'); $query->from('#__menu AS m'); $query->where(' m.link = "index.php?option=com_icagenda&view=list" AND m.published > 0 '); // Filter by language. if ($app->isSite() && JLanguageMultilang::isEnabled()) { $query->where('m.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); } $db->setQuery($query); $idlangtag = $db->loadResult(); $iCmenu = $idlangtag ? $idlangtag : false; // Get User groups allowed to approve event submitted $userID = $user->id; $userLevels = $user->getAuthorisedViewLevels(); if (version_compare(JVERSION, '3.0', 'lt')) { $userGroups = $user->getAuthorisedGroups(); } else { $userGroups = $user->groups; } $groupid = JComponentHelper::getParams('com_icagenda')->get('approvalGroups', array("8")); jimport('joomla.access.access'); $adminUsersArray = array(); foreach ($groupid as $gp) { $adminUsers = JAccess::getUsersByGroup($gp, false); $adminUsersArray = array_merge($adminUsersArray, $adminUsers); } // The database query; $query = $db->getQuery(true); $query->select('a.title AS title, a.created AS created, a.desc AS text, a.id AS eventID, a.language AS language'); $query->select($query->concatenate(array($db->Quote($section), 'c.title'), " / ") . ' AS section'); $query->select('"' . $search_target . '" AS browsernav'); $query->from('#__icagenda_events AS a'); $query->innerJoin('#__icagenda_category as c ON c.id = a.catid'); $query->where('(' . $where . ')' . 'AND a.state = 1 AND a.access IN (' . $groups . ') '); // if user logged-in has no Approval Rights, not approved events won't be displayed. if (!in_array($userID, $adminUsersArray) and !in_array('8', $userGroups)) { $query->where(' a.approval <> 1 '); } // Filter by language. // if ($app->isSite()) if ($app->isSite() && JLanguageMultilang::isEnabled()) { $query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); } $query->order($order); // Set query $db->setQuery($query, 0, $search_limit); $iCevents = $db->loadObjectList(); // $limit -= count($list); // The 'output' of the displayed link. if (isset($iCevents)) { foreach ($iCevents as $key => $iCevent) { $iCevents[$key]->href = 'index.php?option=com_icagenda&view=list&layout=event&id=' . $iCevent->eventID . '&Itemid=' . $iCmenu; } } // If menu item iCagenda list of events exists, returns events found. if ($iCmenu) { //Return the search results in an array return $iCevents; } else { // Displays a warning that no menu item to the list of events is published. $app->enqueueMessage(JText::_('ICAGENDA_PLG_SEARCH_ALERT_NO_ICAGENDA_MENUITEM'), 'warning'); } }
protected function notificationManagerEmail($data, $site_menu_title, $user_id) { $event_id = $data->id; $event_title = $data->title; $event_site_itemid = $data->site_itemid; $event_username = $data->username; $event_user_email = $data->created_by_email; $event_ref = JHtml::date('now', 'Ymd') . $data->id; // Load iCagenda Global Options $iCparams = JComponentHelper::getParams('com_icagenda'); // Load Joomla Application $app = JFactory::getApplication(); // Load Joomla Config Mail Options $sitename = $app->getCfg('sitename'); $mailfrom = $app->getCfg('mailfrom'); $fromname = $app->getCfg('fromname'); $siteURL = JURI::base(); $siteURL = rtrim($siteURL, '/'); // Itemid Request (automatic detection of the first iCagenda menu-link, by menuID, and depending of current language) $menu_items = icagendaMenus::iClistMenuItems(); $itemid_array = array(); foreach ($menu_items as $l) { array_push($itemid_array, $l->id); } sort($itemid_array); $itemID = $itemid_array[0]; // Set Notification Email to each User groups allowed to approve event submitted $groupid = $iCparams->get('approvalGroups', array("8")); // Load Global Option for Autologin $autologin = $iCparams->get('auto_login', 1); jimport('joomla.access.access'); $adminUsersArray = array(); foreach ($groupid as $gp) { $adminUsers = JAccess::getUsersByGroup($gp, False); $adminUsersArray = array_merge($adminUsersArray, $adminUsers); } $db = JFactory::getDbo(); $query = $db->getQuery(true); if ($user_id == NULL) { $user_id = 0; } if (!in_array($user_id, $adminUsersArray)) { $matches = implode(',', $adminUsersArray); $query->select('ui.username AS username, ui.email AS email, ui.password AS passw, ui.block AS block, ui.activation AS activation')->from('#__users AS ui')->where("ui.id IN ({$matches}) "); } else { $matches = $user_id; $query->select('ui.username AS username, ui.email AS email, ui.password AS passw, ui.block AS block, ui.activation AS activation')->from('#__users AS ui')->where("ui.id = {$matches} "); } $db->setQuery($query); $managers = $db->loadObjectList(); foreach ($managers as $manager) { // Mail Replacements $replacements = array("\\n" => "\n", '[SITENAME]' => $sitename, '[USERNAME]' => $event_username, '[EMAIL]' => $event_user_email, '[EVENT_TITLE]' => $event_title, '[EVENT_REF]' => $event_ref, ' ' => ' '); if (!in_array($user_id, $adminUsersArray)) { $type = 'approval'; } else { $type = 'confirmation'; } // Create Admin Mailer $adminmailer = JFactory::getMailer(); // Set Sender of Notification Email $adminmailer->setSender(array($mailfrom, $fromname)); $username = $manager->username; $passw = $manager->passw; $email = $manager->email; // Set Recipient of Notification Email $adminrecipient = $email; $adminmailer->addRecipient($adminrecipient); // Set Subject of Admin Notification Email if (!in_array($user_id, $adminUsersArray)) { $adminsubject = JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_SUBJECT', $event_username, $sitename); } else { $adminsubject = JText::sprintf('COM_ICAGENDA_LEGEND_NEW_EVENT') . ': ' . $event_title; } // Set Url to preview and checking of event submitted $baseURL = JURI::base(); $subpathURL = JURI::base(true); $baseURL = str_replace('/administrator', '', $baseURL); $subpathURL = str_replace('/administrator', '', $subpathURL); if ($autologin == 1) { $urlpreview = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $event_id . '&Itemid=' . (int) $itemID . '&icu=' . $username . '&icp=' . $passw)); // $urlcheck = str_replace('&', '&', JRoute::_('administrator/index.php?option=com_icagenda&view=events&Itemid='.(int)$itemID).'&icu='.$username.'&icp='.$passw.'&filter_search='.$event_id); } else { $urlpreview = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $event_id . '&Itemid=' . (int) $itemID)); // $urlcheck = str_replace('&', '&', JRoute::_('administrator/index.php?option=com_icagenda&view=events&Itemid='.(int)$itemID).'&filter_search='.$event_id); } // $urlpreview = str_replace('&', '&', $siteURL.'/index.php?option=com_icagenda&view=list&layout=event&id='.(int)$event_id.'&Itemid='.(int)$itemID.'&icu='.$username.'&icp='.$passw); $urlpreviewshort = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $event_id . '&Itemid=' . (int) $itemID)); // $urlcheckshort = str_replace('&', '&', $siteURL . '/administrator/index.php?option=com_icagenda&view=events'); // Sub Path filtering $subpathURL = ltrim($subpathURL, '/'); // URL Event Preview filtering $urlpreview = ltrim($urlpreview, '/'); $urlpreviewshort = ltrim($urlpreviewshort, '/'); if (substr($urlpreview, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlpreview = substr($urlpreview, strlen($subpathURL) + 1); } if (substr($urlpreviewshort, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlpreviewshort = substr($urlpreviewshort, strlen($subpathURL) + 1); } $urlpreview = rtrim($baseURL, '/') . '/' . ltrim($urlpreview, '/'); $urlpreviewshort = rtrim($baseURL, '/') . '/' . ltrim($urlpreviewshort, '/'); // URL Event Check filtering // $urlcheck = ltrim($urlcheck, '/'); // if (substr($urlcheck, 0, strlen($subpathURL)+1) == "$subpathURL/") // { // $urlcheck = substr($urlcheck, strlen($subpathURL)+1); // } // $urlcheck = rtrim($baseURL, '/') . '/' . ltrim($urlcheck, '/'); // Set Body of User Notification Email $adminbodycontent = JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_HELLO', $username) . ',<br /><br />'; if ($type == 'approval') { $adminbodycontent .= JText::_('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_NEW_EVENT') . '<br /><br />'; $adminbodycontent .= JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVE_INFO', $sitename) . '<br /><br />'; $adminbodycontent .= JText::_('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVE_LINK') . ': <a href="' . $urlpreview . '">' . $urlpreviewshort . '</a><br /><br />'; } if ($type == 'confirmation') { $adminbodycontent .= JText::_('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVED_REVIEW') . '<br /><br />'; $adminbodycontent .= '<a href="' . $urlpreview . '">' . $urlpreviewshort . '</a><br /><br />'; } $user_email_mailto = '<a href="mailto:' . $event_user_email . '">' . $event_user_email . '</a>'; $adminbodycontent .= JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_SITE_MENUID', $event_site_itemid, $site_menu_title) . '<br />'; $adminbodycontent .= JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_USER_INFO', $event_username, $user_email_mailto) . '<br /><br />'; if ($autologin == 1) { $adminbodycontent .= '<hr><small>' . JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_FOOTER', $sitename) . '<small>'; } else { $adminbodycontent .= '<hr><small>' . JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_FOOTER_NO_AUTOLOGIN', $sitename) . '<small>'; } $adminbody = rtrim($adminbodycontent); // Apply Replacements foreach ($replacements as $key => $value) { $adminsubject = str_replace($key, $value, $adminsubject); $adminbody = str_replace($key, $value, $adminbody); } $adminmailer->isHTML(true); $adminmailer->Encoding = 'base64'; // Set Subject $adminmailer->setSubject($adminsubject); // Set Body $adminmailer->setBody($adminbody); // Send User Notification Email if (isset($email)) { if ($manager->block == '0' && empty($manager->activation)) { $send = $adminmailer->Send(); } } } }
public function testGetUsersByGroup() { if (defined('DB_NOT_AVAILABLE')) { $this->markTestSkipped('The database is not available'); } $access = new JAccess(); $array1 = array( 0 => 42 ); $this->assertThat( $array1, $this->equalTo($access->getUsersByGroup(8, True)) ); $this->assertThat( $array1, $this->equalTo($access->getUsersByGroup(7, True)) ); $array2 = array(); $this->assertThat( $array2, $this->equalTo($access->getUsersByGroup(7, False)) ); }
function save_comment($cachable = false, $urlparams = array()) { JRequest::checkToken(); $app = JFactory::getApplication(); $view = $this->getView('singleimage', 'html'); /** * @var EventgalleryModelSingleimage $model */ $model = $this->getModel('singleimage'); $view->setModel($model); $modelComment = $this->getModel('comment'); $buzzwords = $model->getBuzzwords(); $buzzwordsClean = BuzzwordsHelper::validateBuzzwords($buzzwords, JRequest::getVar('text')); $data = JRequest::getVar('jform', array(), 'post', 'array'); $form = $modelComment->getForm(); $validate = $modelComment->validate($form, $data); if ($validate === false || !$buzzwordsClean) { // Get the validation messages. $errors = $modelComment->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } // Save the data in the session. $app->setUserState('com_eventgallery.comment.data', $data); // Redirect back to the contact form. $msg = JText::_('COM_EVENTGALLERY_SINGLEIMAGE_COMMENT_SAVE_FAILED'); $this->setRedirect(JRoute::_("index.php?view=singleimage&success=false&folder=" . JRequest::getVar('folder') . "&file=" . JRequest::getVar('file'), false), $msg, 'error'); return false; } $validate['file'] = JRequest::getString('file'); $validate['folder'] = JRequest::getString('folder'); $row = $model->store_comment($validate, $buzzwordsClean ? 1 : 0); // reset the user state $app->setUserState('com_eventgallery.comment.data', null); $msg = JText::_('COM_EVENTGALLERY_SINGLEIMAGE_COMMENT_SAVE_SUCCESS'); $this->setRedirect(JRoute::_("index.php?view=singleimage&success=true&folder=" . JRequest::getVar('folder') . "&file=" . JRequest::getVar('file'), false), $msg, 'success'); $mailer = JFactory::getMailer(); $params = JComponentHelper::getParams('com_eventgallery'); $userids = JAccess::getUsersByGroup($params->get('admin_usergroup')); if (count($userids) == 0) { return; } foreach ($userids as $userid) { $user = JUser::getInstance($userid); if ($user->sendEmail == 1) { $mailadress = JMailHelper::cleanAddress($user->email); $mailer->addRecipient($mailadress); } } $config = JFactory::getConfig(); $sender = array($config->get('mailfrom'), $config->get('fromname')); $mailer->setSender($sender); JRequest::setVar('newCommentId', $row->id); $mailview = $this->getView('commentmail', 'html'); /** * * @var EventgalleryModelComment $commentModel */ $commentModel = $this->getModel('comment'); $mailview->setModel($commentModel, true); $bodytext = $mailview->loadTemplate(); #$mailer->LE = "\r\n"; $mailer->LE = "\n"; $bodytext = JMailHelper::cleanBody($bodytext); $mailer->setSubject(JMailHelper::cleanSubject($row->folder . "|" . $row->file . ' - ' . JText::_('COM_EVENTGALLERY_COMMENT_ADD_MAIL_SUBJECT') . ' - ' . $app->getCfg('sitename'))); $mailer->SetBody($bodytext); $mailer->IsHTML(true); $mailer->Send(); }
// No direct access to this file defined('_JEXEC') or die; // Get the site name $sitename = JFactory::getApplication()->getCfg('sitename'); // Get Component Global Options $iCparams = JComponentHelper::getParams('com_icagenda'); // Get Authorized user groups (approval managers) $approvalGroups = $iCparams->get('approvalGroups', array("8")); // Get User $user = JFactory::getUser(); $u_id = $user->get('id'); // Control: if Manager jimport('joomla.access.access'); $adminUsersArray = array(); foreach ($approvalGroups as $ag) { $adminUsers = JAccess::getUsersByGroup($ag, False); $adminUsersArray = array_merge($adminUsersArray, $adminUsers); } $isManager = in_array($u_id, $adminUsersArray) ? true : false; //$urllink = JURI::getInstance()->toString(); //$urllink = preg_replace('/&view=[^&]*/', '', $urllink); //$urlNewEvent = preg_replace('/&layout=[^&]*/', '', $urllink); $urlNewEvent = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=submit')); // clear the data so we don't process it again $session = JFactory::getSession(); $session->clear('ic_submit'); $session->clear('custom_fields'); $session->clear('ic_submit_dates'); $session->clear('ic_submit_catid'); $session->clear('ic_submit_shortdesc'); $session->clear('ic_submit_metadesc');
function edit($tpl = null) { // WHY THE HELL DO THEY BREAK PUBLIC FUNCTIONS !!! if (JVersion::isCompatible("1.6.0")) { JHTML::stylesheet('administrator/components/' . JEV_COM_COMPONENT . '/assets/css/eventsadmin.css'); } else { JHTML::stylesheet('eventsadmin.css', 'administrator/components/' . JEV_COM_COMPONENT . '/assets/css/'); } JEVHelper::script('editical.js', 'administrator/components/' . JEV_COM_COMPONENT . '/assets/js/'); $document =& JFactory::getDocument(); $document->setTitle(JText::_('EDIT_ICS')); // Set toolbar items for the page JToolBarHelper::title(JText::_('EDIT_ICS'), 'jevents'); //JToolBarHelper::save('icals.save'); $bar =& JToolBar::getInstance('toolbar'); if ($this->editItem && isset($this->editItem->ics_id) && $this->editItem->ics_id > 0) { JToolBarHelper::save('icals.savedetails'); } JToolBarHelper::cancel('icals.list'); //JToolBarHelper::help( 'screen.icals.edit', true); $this->_hideSubmenu(); $params = JComponentHelper::getParams(JEV_COM_COMPONENT); //$section = $params->getValue("section",0); $db = JFactory::getDbo(); if ($params->getValue("authorisedonly", 0)) { // get authorised users $sql = "SELECT u.* FROM #__jev_users as jev LEFT JOIN #__users as u on u.id=jev.user_id where jev.published=1 and jev.cancreate=1"; $db =& JFactory::getDBO(); $db->setQuery($sql); $users = $db->loadObjectList(); } else { if (JVersion::isCompatible("1.6.0")) { $rules = JAccess::getAssetRules("com_jevents", true); $creatorgroups = $rules->getData(); // need to merge the arrays because of stupid way Joomla checks super user permissions $creatorgroups = array_merge($creatorgroups["core.admin"]->getData(), $creatorgroups["core.create"]->getData()); $users = array(0); foreach ($creatorgroups as $creatorgroup => $permission) { if ($permission == 1) { $users = array_merge(JAccess::getUsersByGroup($creatorgroup, true), $users); } } $sql = "SELECT * FROM #__users where id IN (" . implode(",", array_values($users)) . ") ORDER BY name asc"; $db->setQuery($sql); $users = $db->loadObjectList(); } else { $minaccess = $params->getValue("jevcreator_level", 19); // get users AUTHORS and above $sql = "SELECT * FROM #__users where gid>=" . $minaccess; $db->setQuery($sql); $users = $db->loadObjectList(); } } $userOptions = array(); foreach ($users as $user) { $userOptions[] = JHTML::_('select.option', $user->id, $user->name . " ({$user->username})"); } $jevuser =& JFactory::getUser(); if ($this->editItem && isset($this->editItem->ics_id) && $this->editItem->ics_id > 0 && $this->editItem->created_by > 0) { $created_by = $this->editItem->created_by; } else { $created_by = $jevuser->id; } if (count($userOptions) > 0) { $userlist = JHTML::_('select.genericlist', $userOptions, 'created_by', 'class="inputbox" size="1" ', 'value', 'text', $created_by); } else { $userList = ""; } $this->assignRef("users", $userlist); JHTML::_('behavior.tooltip'); }
public static function getUsersByGroup($gid) { $userArr = array(); if (Komento::joomlaVersion() >= '1.6') { $userArr = JAccess::getUsersByGroup($gid); } else { $sql = Komento::getSql(); $sql->select('#__users')->column('id')->where('gid', $gid); $userArr = $sql->loadResultArray(); } return $userArr; }
/** * The sql must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * * @param string Target search string * @param string mathcing option, exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category * @param mixed An array if the search it to be restricted to areas, null if search all */ function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $db = JFactory::getDBO(); $app = JFactory::getApplication(); $tag = JFactory::getLanguage()->getTag(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); // If the array is not correct, return it: if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } // Now retrieve the plugin parameters $search_name = $this->params->get('search_name', JText::_('ICAGENDA_PLG_SEARCH_SECTION_EVENTS')); if ($search_name == 'ICAGENDA_PLG_SEARCH_SECTION_EVENTS') { $search_name = 'Events'; } $search_limit = $this->params->get('search_limit', '50'); $search_target = $this->params->get('search_target', '0'); // Use the PHP function trim to delete spaces in front of or at the back of the searching terms $text = trim($text); // Return Array when nothing was filled in. if ($text == '') { return array(); } // Database part. $wheres = array(); switch ($phrase) { // Search exact case 'exact': $text = $db->Quote('%' . $db->escape($text, true) . '%', false); $wheres2 = array(); $wheres2[] = 'LOWER(e.title) LIKE ' . $text; $wheres2[] = 'LOWER(e.shortdesc) LIKE ' . $text; $wheres2[] = 'LOWER(e.desc) LIKE ' . $text; $wheres2[] = 'LOWER(e.metadesc) LIKE ' . $text; $wheres2[] = 'LOWER(e.place) LIKE ' . $text; $wheres2[] = 'LOWER(e.city) LIKE ' . $text; $wheres2[] = 'LOWER(e.country) LIKE ' . $text; $wheres2[] = 'LOWER(e.address) LIKE ' . $text; $wheres2[] = 'LOWER(c.title) LIKE ' . $text; $where = '(' . implode(') OR (', $wheres2) . ')'; break; // Search all or any // Search all or any case 'all': case 'any': // Set default // Set default default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->Quote('%' . $db->escape($word, true) . '%', false); $wheres2 = array(); $wheres2[] = 'LOWER(e.title) LIKE ' . $word; $wheres2[] = 'LOWER(e.shortdesc) LIKE ' . $word; $wheres2[] = 'LOWER(e.desc) LIKE ' . $word; $wheres2[] = 'LOWER(e.metadesc) LIKE ' . $word; $wheres2[] = 'LOWER(e.place) LIKE ' . $word; $wheres2[] = 'LOWER(e.city) LIKE ' . $word; $wheres2[] = 'LOWER(e.country) LIKE ' . $word; $wheres2[] = 'LOWER(e.address) LIKE ' . $word; $wheres2[] = 'LOWER(c.title) LIKE ' . $word; $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } // Ordering of the results switch ($ordering) { //Alphabetic, ascending case 'alpha': $order = 'e.title ASC'; break; // Oldest first // Oldest first case 'oldest': $order = 'e.next ASC'; break; // Popular first // Popular first case 'popular': // Newest first // Newest first case 'newest': $order = 'e.next DESC'; break; // Category // Category case 'category': $order = 'c.title ASC'; break; // Default setting: alphabetic, ascending // Default setting: alphabetic, ascending default: $order = 'e.title ASC'; } // Section $section = $search_name; // List of Events menu Itemid Request $iC_list_menus = self::iClistMenuItemsInfo(); $nb_menu = count($iC_list_menus); $nolink = $nb_menu ? false : true; // Get User groups allowed to approve event submitted $userID = $user->id; $userLevels = $user->getAuthorisedViewLevels(); if (version_compare(JVERSION, '3.0', 'lt')) { $userGroups = $user->getAuthorisedGroups(); } else { $userGroups = $user->groups; } $groupid = JComponentHelper::getParams('com_icagenda')->get('approvalGroups', array("8")); jimport('joomla.access.access'); $adminUsersArray = array(); foreach ($groupid as $gp) { $adminUsers = JAccess::getUsersByGroup($gp, false); $adminUsersArray = array_merge($adminUsersArray, $adminUsers); } // The database query; $query = $db->getQuery(true); $query->select('e.title AS title, e.created AS created, e.next AS next, e.displaytime AS displaytime, e.desc AS text, e.id AS eventID, e.alias AS alias, c.id AS catid, e.language AS language'); $query->select($query->concatenate(array($db->Quote($section), 'c.title'), " / ") . ' AS section'); $query->select('"' . $search_target . '" AS browsernav'); $query->from('#__icagenda_events AS e'); $query->innerJoin('#__icagenda_category as c ON c.id = e.catid'); $query->where('c.state = 1'); // START Hack for Upcoming Filtering // $datetime_today = JHtml::date('now', 'Y-m-d H:i'); // Joomla Time Zone // $query->where('e.next >= ' . $db->q($datetime_today)); // END Hack for Upcoming Filtering $query->where('(' . $where . ')' . 'AND e.state = 1 AND e.access IN (' . $groups . ') '); // if user logged-in has no Approval Rights, not approved events won't be displayed. if (!in_array($userID, $adminUsersArray) and !in_array('8', $userGroups)) { $query->where(' e.approval <> 1 '); } // Filter by language. if ($app->isSite() && JLanguageMultilang::isEnabled()) { $query->where('e.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); } $query->order($order); // Set query $db->setQuery($query, 0, $search_limit); $iCevents = $db->loadObjectList(); // $limit -= count($list); // The 'output' of the displayed link. if (isset($iCevents)) { foreach ($iCevents as $key => $iCevent) { // set menu link for each event (itemID) depending of category and/or language $onecat = $multicat = '0'; $link_one = $link_multi = ''; $item_catid = $iCevent->catid; $array_menus_cat_not_set = array(); foreach ($iC_list_menus as $iCm) { $value = explode('-', $iCm); $iCmenu_id = $value['0']; $iCmenu_mcatid = $value['1']; $iCmenu_lang = $value['2']; $iCmenu_mcatid_array = !is_array($iCmenu_mcatid) ? explode(',', $iCmenu_mcatid) : ''; if ($iCmenu_mcatid && $iCmenu_lang == $iCevent->language) { $nb_cat_filter = count($iCmenu_mcatid_array); for ($i = $iCevent->catid; in_array($i, $iCmenu_mcatid_array); $i++) { if ($nb_cat_filter == 1) { $link_one = $iCmenu_id; } elseif ($nb_cat_filter > 1) { $link_multi = $iCmenu_id; } } } else { array_push($array_menus_cat_not_set, $iCmenu_id); } } if ($link_one) { $linkid = $link_one; } elseif ($link_multi) { $linkid = $link_multi; } else { $linkid = count($array_menus_cat_not_set) ? $array_menus_cat_not_set['0'] : null; } $event_slug = empty($iCevent->alias) ? $iCevent->eventID : $iCevent->eventID . ':' . $iCevent->alias; $date_next = JHtml::date($iCevent->next, JText::_('DATE_FORMAT_LC3'), null); $time_next = JHtml::date($iCevent->next, 'H:i', null); $display_time = $iCevent->displaytime ? ' ' . $time_next : ''; $iCevents[$key]->title = $iCevent->title . ' (' . $date_next . $display_time . ')'; $iCevents[$key]->href = 'index.php?option=com_icagenda&view=list&layout=event&id=' . $event_slug . '&Itemid=' . $linkid; } } // If menu item iCagenda list of events exists, returns events found. if ($nolink) { // Displays a warning that no menu item to the list of events is published. $app->enqueueMessage(JText::_('ICAGENDA_PLG_SEARCH_ALERT_NO_ICAGENDA_MENUITEM'), 'warning'); } else { //Return the search results in an array return $iCevents; } }
/** * Tests the JAccess::getUsersByGroup method. * * @return void * * @since 11.1 */ public function testGetUsersByGroupInvalidGroup() { $access = new JAccess(); $array2 = array(); $this->assertThat($access->getUsersByGroup(15, false), $this->equalTo($array2), 'No group specified. Line: ' . __LINE__); }
/** * Helper wrapper method for getUsersByGroup * * @param integer $groupId The group Id * @param boolean $recursive Recursively include all child groups (optional) * * @return array * * @see JAccess::getUsersByGroup() * @since 3.4 */ public function getUsersByGroup($groupId, $recursive = false) { return JAccess::getUsersByGroup($groupId, $recursive); }
protected function setCreatorLookup() { // If user is jevents can deleteall or has backend access then allow them to specify the creator $jevuser = JEVHelper::getAuthorisedUser(); $user = JFactory::getUser(); if (JVersion::isCompatible("1.6.0")) { //$access = JAccess::check($user->id, "core.deleteall", "com_jevents"); $access = $user->authorise('core.admin', 'com_jevents'); } else { // Get an ACL object $acl =& JFactory::getACL(); $grp = $acl->getAroGroup($user->get('id')); // if no valid group (e.g. anon user) then skip this. if (!$grp) { return; } $access = $acl->is_group_child_of($grp->name, 'Public Backend'); } $db = JFactory::getDBO(); if ($jevuser && $jevuser->candeleteall || $access) { if (JVersion::isCompatible("1.6.0")) { $params =& JComponentHelper::getParams(JEV_COM_COMPONENT); $authorisedonly = $params->get("authorisedonly", 0); // if authorised only then load from database if ($authorisedonly) { $sql = "SELECT tl.*, ju.* FROM #__jev_users AS tl "; $sql .= " LEFT JOIN #__users as ju ON tl.user_id=ju.id "; $sql .= " WHERE tl.cancreate=1"; $sql .= " ORDER BY ju.name ASC"; $db->setQuery($sql); $users = $db->loadObjectList(); } else { $rules = JAccess::getAssetRules("com_jevents", true); $creatorgroups = $rules->getData(); // need to merge the arrays because of stupid way Joomla checks super user permissions //$creatorgroups = array_merge($creatorgroups["core.admin"]->getData(), $creatorgroups["core.create"]->getData()); // use union orf arrays sincee getData no longer has string keys in the resultant array //$creatorgroups = $creatorgroups["core.admin"]->getData()+ $creatorgroups["core.create"]->getData(); // use union orf arrays sincee getData no longer has string keys in the resultant array $creatorgroupsdata = $creatorgroups["core.admin"]->getData(); // take the higher permission setting foreach ($creatorgroups["core.create"]->getData() as $creatorgroup => $permission) { if ($permission) { $creatorgroupsdata[$creatorgroup] = $permission; } } $users = array(0); foreach ($creatorgroupsdata as $creatorgroup => $permission) { if ($permission == 1) { $users = array_merge(JAccess::getUsersByGroup($creatorgroup, true), $users); } } $sql = "SELECT * FROM #__users where id IN (" . implode(",", array_values($users)) . ") ORDER BY name asc"; $db->setQuery($sql); $users = $db->loadObjectList(); } } else { $db = JFactory::getDBO(); $params =& JComponentHelper::getParams(JEV_COM_COMPONENT); $authorisedonly = $params->get("authorisedonly", 0); // if authorised only then load from database if ($authorisedonly) { $sql = "SELECT tl.*, ju.* FROM #__jev_users AS tl "; $sql .= " LEFT JOIN #__users as ju ON tl.user_id=ju.id "; $sql .= " WHERE tl.cancreate=1"; $sql .= " ORDER BY ju.name ASC"; $db->setQuery($sql); $users = $db->loadObjectList(); } else { $params =& JComponentHelper::getParams(JEV_COM_COMPONENT); $minaccess = $params->getValue("jevcreator_level", 19); $sql = "SELECT * FROM #__users where gid>=" . $minaccess; $sql .= " ORDER BY name ASC"; $db->setQuery($sql); $users = $db->loadObjectList(); } } $userOptions[] = JHTML::_('select.option', '-1', JText::_('SELECT_USER')); foreach ($users as $user) { $userOptions[] = JHTML::_('select.option', $user->id, $user->name . " ( " . $user->username . " )"); } $creator = $this->row->created_by() > 0 ? $this->row->created_by() : (isset($jevuser) ? $jevuser->user_id : 0); $userlist = JHTML::_('select.genericlist', $userOptions, 'jev_creatorid', 'class="inputbox" size="1" ', 'value', 'text', $creator); $this->assignRef("users", $userlist); } }
/** * @return array */ protected function _getRecipients() { $recipients = $this->app->data->create($this->config->get('recipients')); $tmpResult = array(); // get by groups if ($groups = $recipients->get('groups')) { foreach ($groups as $groupId) { if ($users = JAccess::getUsersByGroup($groupId)) { foreach ($users as $userId) { $juser = JFactory::getUser($userId); $tmpResult[] = array($juser->email, $juser->name); } } } } // get by orderform $orderform = (array) $recipients->get('orderform', array()); foreach ($orderform as $field) { if ($field == self::FIELD_SITEMAIL) { $config = JFactory::getConfig(); $tmpResult[] = array($config->get('mailfrom'), $config->get('sitename')); } else { if ($field == self::FIELD_USERMAIL) { $juser = JFactory::getUser(); $tmpResult[] = array($juser->email, $juser->name); } else { if ($element = $this->getOrder()->getFieldElement($field)) { $value = $element->data()->get('value'); $tmpResult[] = array($value, $value); } } } } // get custom fields $custom = explode(',', $recipients->get('custom')); foreach ($custom as $email) { $tmpResult[] = array($email, $email); } // check and clear all recipients $result = array(); foreach ($tmpResult as $recipient) { list($email, $name) = $recipient; if ($email = $this->app->jbvars->email($email)) { if (!isset($result[$email])) { $result[$email] = JString::trim($name); } } } return $result; }
public function send() { $app = JFactory::getApplication(); $data = $app->input->post->get('jform', array(), 'array'); $user = JFactory::getUser(); $access = new JAccess(); $db = $this->getDbo(); $mode = array_key_exists('mode', $data) ? (int) $data['mode'] : 0; $subject = array_key_exists('subject', $data) ? $data['subject'] : ''; $grp = array_key_exists('group', $data) ? (int) $data['group'] : 0; $recurse = array_key_exists('recurse', $data) ? (int) $data['recurse'] : 0; $bcc = array_key_exists('bcc', $data) ? (int) $data['bcc'] : 0; $disabled = array_key_exists('disabled', $data) ? (int) $data['disabled'] : 0; $message_body = array_key_exists('message', $data) ? $data['message'] : ''; // automatically removes html formatting if (!$mode) { $message_body = JFilterInput::getInstance()->clean($message_body, 'string'); } // Check for a message body and subject if (!$message_body || !$subject) { $app->setUserState('com_users.display.mail.data', $data); $this->setError(JText::_('COM_USERS_MAIL_PLEASE_FILL_IN_THE_FORM_CORRECTLY')); return false; } // get users in the group out of the acl $to = $access->getUsersByGroup($grp, $recurse); // Get all users email and group except for senders $query = $db->getQuery(true); $query->select('email'); $query->from('#__users'); $query->where('id != ' . (int) $user->get('id')); if ($grp !== 0) { if (empty($to)) { $query->where('0'); } else { $query->where('id IN (' . implode(',', $to) . ')'); } } if ($disabled == 0) { $query->where("block = 0"); } $db->setQuery($query); $rows = $db->loadColumn(); // Check to see if there are any users in this group before we continue if (!count($rows)) { $app->setUserState('com_users.display.mail.data', $data); if (in_array($user->id, $to)) { $this->setError(JText::_('COM_USERS_MAIL_ONLY_YOU_COULD_BE_FOUND_IN_THIS_GROUP')); } else { $this->setError(JText::_('COM_USERS_MAIL_NO_USERS_COULD_BE_FOUND_IN_THIS_GROUP')); } return false; } // Get the Mailer $mailer = JFactory::getMailer(); $params = JComponentHelper::getParams('com_users'); // Build email message format. $mailer->setSender(array($app->getCfg('mailfrom'), $app->getCfg('fromname'))); $mailer->setSubject($params->get('mailSubjectPrefix') . stripslashes($subject)); $mailer->setBody($message_body . $params->get('mailBodySuffix')); $mailer->IsHTML($mode); // Add recipients if ($bcc) { $mailer->addBCC($rows); $mailer->addRecipient($app->getCfg('mailfrom')); } else { $mailer->addRecipient($rows); } // Send the Mail $rs = $mailer->Send(); // Check for an error if ($rs instanceof Exception) { $app->setUserState('com_users.display.mail.data', $data); $this->setError($rs->getError()); return false; } elseif (empty($rs)) { $app->setUserState('com_users.display.mail.data', $data); $this->setError(JText::_('COM_USERS_MAIL_THE_MAIL_COULD_NOT_BE_SENT')); return false; } else { // Fill the data (specially for the 'mode', 'group' and 'bcc': they could not exist in the array // when the box is not checked and in this case, the default value would be used instead of the '0' // one) $data['mode'] = $mode; $data['subject'] = $subject; $data['group'] = $grp; $data['recurse'] = $recurse; $data['bcc'] = $bcc; $data['message'] = $message_body; $app->setUserState('com_users.display.mail.data', array()); $app->enqueueMessage(JText::plural('COM_USERS_MAIL_EMAIL_SENT_TO_N_USERS', count($rows)), 'message'); return true; } }
/** * Метод для отправки оповещения редакторам * @param integer $catid ID категории * @param string $name Автор вопроса */ protected function sendMail($data, &$category) { $params = $category->getParams(); // отключение if ($params->get('disabled_mail')) { return true; } $rules = JAccess::getAssetRules('com_smfaq.category.' . $category->id, false); $r = $rules->getData(); $group = $r['core.edit']->getData(); if (is_array($group) && count($group) > 0) { foreach ($group as $key => $value) { if ($value == 1) { $groups[] = JAccess::getUsersByGroup($key); } } if (isset($groups)) { $users_id = array(); foreach ($groups as $group) { if ($group) { for ($i = 0; $i < count($group); $i++) { $users_id[] = $group[$i]; } } } if (count($users_id) > 0) { $users_id = implode(",", array_unique($users_id)); $db = JFactory::getDBO(); $query = 'SELECT email FROM #__users WHERE id IN (' . $users_id . ')'; $db->setQuery($query); $emails = $db->loadResultArray(); if ($emails) { $config = JFactory::getConfig(); $mailfrom = $config->get('mailfrom'); $fromname = $config->get('fromname'); $date = JFactory::getDate(null, $config->get('offset')); $date = $date->format('d.m.Y H:i'); $link = JURI::root() . 'index.php?option=com_smfaq&task=edit.edit&id=' . $this->getState('smfaq.id') . '&catid=' . $category->id; $subject = JText::sprintf('COM_SMFAQ_MAIL_SUBJECT_NEW', $category->title); $message = JText::sprintf('COM_SMFAQ_MAIL_MESSAGE_NEW', $data['created_by'], $date, $data['question'], $link); $mail = JFactory::getMailer(); // if (($mail->Mailer == 'mail') && ! function_exists('mail')) { // return false; // } foreach ($emails as $email) { $send = $mail->sendMail($mailfrom, $fromname, $email, $subject, $message); if ($send !== true) { return false; } } } } } } else { } return true; }