public function execute() { $ids = waRequest::request('id', array(), 'array_int'); if (!$ids) { throw new waException('Contact id not specified.'); } // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException(_w('Access denied')); } $groups = waRequest::post('groups', array(), 'array_int'); $counters = array(); $ugm = new waUserGroupsModel(); if ($this->getRequest()->request('set')) { foreach ($ids as $id) { $ugm->delete($id, array()); } } foreach ($ids as $id) { if ($groups) { $ugm->add(array_map(wa_lambda('$gid', 'return array(' . $id . ', $gid);'), $groups)); } } $gm = new waGroupModel(); foreach ($groups as $gid) { $cnt = $ugm->countByField(array('group_id' => $gid)); $gm->updateCount($gid, $cnt); $counters[$gid] = $cnt; } $this->response['counters'] = $counters; $this->response['message'] = _w("%d user has been added", "%d users have been added", count($ids)); $this->response['message'] .= ' '; $this->response['message'] .= _w("to %d group", "to %d groups", count($groups)); }
public function execute() { // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException(_w('Access denied')); } $contact_id = waRequest::get('id'); $group_ids = null; if ($contact_id > 0) { $user_groups_model = new waUserGroupsModel(); $group_ids = $user_groups_model->getGroupIds($contact_id); $group_ids[] = 0; } $app_id = waRequest::get('app'); $right_model = new waContactRightsModel(); $rights = $right_model->get($contact_id, $app_id, null, false); $group_rights = null; if ($group_ids) { $group_rights = $right_model->get(array_map(wa_lambda('$a', 'return -$a;'), $group_ids), $app_id, null, false); } // Check custom rights items $app_config = SystemConfig::getAppConfig($app_id); $class_name = $app_config->getPrefix() . "RightConfig"; $file_path = $app_config->getAppPath('lib/config/' . $class_name . ".class.php"); if (file_exists($file_path)) { // Init app waSystem::getInstance($app_id, $app_config, true); include $file_path; /** * @var waRightConfig $right_config */ $right_config = new $class_name(); $rights += $right_config->getRights($contact_id); if ($group_ids) { $group_rights += $right_config->getRights(array_map(wa_lambda('$a', 'return -$a;'), $group_ids)); } $this->view->assign('html', $right_config->getHTML($rights, $group_rights)); waSystem::setActive('contacts'); } else { $this->view->assign('html', ''); } if ($contact_id > 0) { $this->view->assign('user', new waContact($contact_id)); } else { $gm = new waGroupModel(); $this->view->assign('group', $gm->getById(-$contact_id)); } $app = wa()->getAppInfo($app_id); $app['id'] = $app_id; $this->view->assign('app', $app); $this->view->assign('rights', $rights); $this->view->assign('group_rights', $group_rights); }
public function execute() { if (!($id = (int) waRequest::get('id'))) { throw new waException('Contact id not specified.'); } // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException('Access denied.'); } $groups = waRequest::post('groups', array(), 'array_int'); $ugm = new waUserGroupsModel(); $ugm->delete($id, array()); if ($groups) { $ugm->add(array_map(wa_lambda('$gid', 'return array(' . $id . ', $gid);'), $groups)); } $this->response = 'ok'; }
public function addTag($post_id, $tags) { if ($tags) { $tags_escape = $this->escape($tags); $tags_escape = array_map(wa_lambda('$tag', 'return "\'{$tag}\'";'), $tags_escape); $tag_installed = $this->select('id, name')->where('name IN (' . implode(",", $tags_escape) . ')')->fetchAll('id', true); $tag_add = array_diff($tags, $tag_installed); if (!empty($tag_add)) { foreach ($tag_add as $tag) { $tag_id = $this->insert(array('name' => $tag)); $tag_installed[$tag_id] = $tag; } } $tag_installed = array_keys($tag_installed); } else { $tag_installed = array(); } $tags_ids = $this->query("SELECT tag_id FROM `blog_post_tag` WHERE `post_id` = i:post_id", array('post_id' => $post_id))->fetchAll('tag_id'); $tags_ids = array_keys($tags_ids); // delete $ids_delete = array_diff($tags_ids, $tag_installed); // add $ids_add = array_diff($tag_installed, $tags_ids); if (!empty($ids_add)) { $ids = array(); foreach ($ids_add as $key => $id) { $ids[$key] = $post_id . ',' . $id; } $data = '(' . implode('),(', $ids) . ')'; $this->exec("INSERT INTO `blog_post_tag` (`post_id`, `tag_id`) VALUES {$data}"); } if (!empty($ids_delete)) { $ids = array(); foreach ($ids_delete as $key => $id) { $ids[$key] = '( post_id=' . $post_id . ' AND ' . 'tag_id=' . $id . ')'; } $data = implode('OR', $ids); $this->exec("DELETE FROM `blog_post_tag` WHERE {$data}"); $tag_count = $this->query("\n\t\t\t\tSELECT tag_id, COUNT(tag_id) as count\n\t\t\t\tFROM blog_post_tag\n\t\t\t\tWHERE tag_id IN (" . implode(',', $ids_delete) . ")")->fetchAll('tag_id'); $empty_tag = array_diff($ids_delete, array_keys($tag_count)); if (!empty($empty_tag)) { $this->deleteByField('id', $empty_tag); } } }
public function execute() { $this->tm = $tm = new shopTaxModel(); $taxes = $tm->getAll('id'); $tax_id = waRequest::request('id'); if (!$tax_id) { $tax_id = $taxes ? key($taxes) : 'new'; } if (!empty($taxes[$tax_id])) { $tax = $taxes[$tax_id]; } else { if ($tax_id == 'new') { $tax = $tm->getEmptyRow(); $tax_id = null; } else { throw new waException('Tax record not found.', 404); } } $this->trm = $trm = new shopTaxRegionsModel(); $this->tzcm = $tzcm = new shopTaxZipCodesModel(); $countries = $this->getCountryList(); $tax = $this->processPostData($tax); if ($tax['id'] && !$tax_id) { $tax_id = $tax['id']; } if ($tax_id) { $taxes[$tax_id] = $tax; } uasort($taxes, wa_lambda('$a,$b', 'return strcmp($a["name"], $b["name"]);')); $this->view->assign('tax_countries', $this->getTaxCountries($tax, $countries)); $this->view->assign('tax_zip_codes', $this->getTaxZipCodes($tax)); $this->view->assign('countries', $countries); $this->view->assign('taxes', $taxes); $this->view->assign('tax', $tax); $checkout_settings = $this->getConfig()->getCheckoutSettings(); $this->view->assign('billing_address_required', isset($checkout_settings['contactinfo']['fields']['address.billing'])); }
/** * @param array $ids list of contact (if positive) or group (if negative) ids. * @return array id => admin|custom; for users with no access at all there's no key=>value pair. */ public function getAccessStatus($ids) { if (!$ids) { return array(); } // Additional groups we need to get access info for. // $group_ids = list of (negative) group ids that users from $ids are members of. $user_groups_model = new waUserGroupsModel(); $user_group = $user_groups_model->getGroupIdsForUsers($ids); // ignores negative ids, so it's ok to pass group ids there $group_ids = array(); foreach ($user_group as $user_group_ids) { $group_ids = array_merge($group_ids, $user_group_ids); } $group_ids = array_map(wa_lambda('$a', 'return -$a;'), $group_ids); $sql = "SELECT -group_id AS id, MAX(CASE app_id WHEN 'webasyst' THEN 2 ELSE 1 END) AS status\n FROM `{$this->table}`\n WHERE -group_id IN (i:ids) AND name='backend'\n GROUP BY group_id"; $result = $this->query($sql, array('ids' => array_merge($ids, $group_ids)))->fetchAll('id', true); // update result considering group rights for users foreach ($ids as $id) { if (!isset($result[$id])) { $result[$id] = 0; } if (isset($user_group[$id]) && $result[$id] <= 1) { foreach ($user_group[$id] as $gid) { if (isset($result[-$gid]) && $result[-$gid] > $result[$id]) { $result[$id] = $result[-$gid]; } if ($result[$id] > 1) { break; } } } if ($result[$id]) { $result[$id] = $result[$id] > 1 ? 'admin' : 'custom'; } else { unset($result[$id]); } } // Remove from results all groups that we added temporary foreach ($group_ids as $gid) { if (isset($result[$gid])) { unset($result[$gid]); } } return $result; }