Ejemplo n.º 1
0
 public function down()
 {
     $this->dbforge->drop_table('conf');
     $this->dbforge->drop_table('locations');
     if (Modules::exists('locazip')) {
         $this->dbforge->drop_table('companies');
         $this->dbforge->drop_table('companies_locations');
     }
 }
 function delete($id)
 {
     $object = $this->get($id);
     $this->db->where('id', $id);
     $this->db->delete('locations');
     /* update products if any */
     if (isset($object['products'])) {
         $products_changed = FALSE;
         $current_products = $this->app_conf->get('products');
         $current_products = strlen($current_products) ? explode('||', $current_products) : array();
         reset($current_products);
         $current_products2 = array();
         foreach ($current_products as $cp) {
             $current_products2[$cp] = 1;
         }
         $products = $object['products'];
         $products = explode(',', $products);
         $products = array_map('trim', $products);
         reset($products);
         foreach ($products as $pn) {
             if (strlen($pn)) {
                 // check if we still have something
                 $this->db->like('products', $pn);
                 $remaining_count = $this->count_all();
                 if (!$remaining_count) {
                     if (isset($current_products2[$pn])) {
                         unset($current_products2[$pn]);
                         $products_changed = TRUE;
                     }
                 }
             }
         }
         if ($products_changed) {
             $value = join('||', array_keys($current_products2));
             $this->app_conf->set('products', $value);
         }
     }
     //delete references to this item
     /*
     		$this->db->where('location_id', $id);
     		$this->db->delete('locations_categories');
     */
     if (Modules::exists('locazip')) {
         $this->db->where('location_id', $id);
         $this->db->delete('companies_locations');
     }
 }
Ejemplo n.º 3
0
							<a href="<?php 
        echo ci_site_url('pro/admin/conf/form');
        ?>
"><?php 
        echo lang('menu_conf_form');
        ?>
</a>
						</li>
					<?php 
    }
    ?>
					</ul>
				</li>

				<?php 
    if (Modules::exists('pro')) {
        ?>
					<li>
						<a href="<?php 
        echo ci_site_url('pro/admin/stats');
        ?>
"><?php 
        echo lang('menu_stats');
        ?>
</a>
					</li>
				<?php 
    }
    ?>
				<li>
					<a href="<?php 
Ejemplo n.º 4
0
	function editAction()
	{
		$request = new RivetyCore_Request($this->getRequest());

		$modules_table = new Modules('modules');
		$modules_table_core = new Modules('core');

		$roles_resources_table = new RolesResources();
		$roles_res_extra_table = new RolesResourcesExtra();

		if ($request->has("id"))
		{
			$role_id = $request->id;
			$roles_table = new Roles();
			$role = $roles_table->fetchRow("id = " . $role_id);
			if (!is_null($role))
			{
				$this->view->role = $role->toArray();
				$this->view->roleshortname = $role->shortname;
			}
			else
			{
				$this->_redirect("/role");
			}
		}
		else
		{
			$this->_redirect("/role");
		}

		if ($request->has("modid"))
		{
			if ($modules_table->exists($request->modid))
			{
				$module_id = $request->modid;
			}
			else
			{
				$module_id = "default";
			}
		}
		else
		{
			$module_id = "default";
		}

		if ($this->getRequest()->isPost())
		{
			$resources = $this->getRequest()->getPost('resource');

			// Hose everything for this role and module
			$where = $roles_resources_table->getAdapter()->quoteInto("role_id = ? and ", $role_id);
			$where .= $roles_resources_table->getAdapter()->quoteInto("module = ? ", $module_id);
			$roles_resources_table->delete($where);

			foreach ($resources as $resource)
			{
				$resource_array = explode("-", $resource);
				$resource_module = $resource_array[0];
				$resource_controller = $resource_array[1];
				$resource_action = $resource_array[2];
				$data = array(
					'role_id' => $role_id,
					'module' => $resource_module,
					'controller' => $resource_controller,
					'action' => $resource_action,
				);
				$roles_resources_table->insert($data);
			}

			$where = $roles_res_extra_table->getAdapter()->quoteInto("role_id = ? and ", $role_id);
			$where .= $roles_res_extra_table->getAdapter()->quoteInto("module = ? ", $module_id);
			$roles_res_extra_table->delete($where);

			if ($request->has("extra_resource"))
			{
				foreach ($request->extra_resource as $extra_resource_item)
				{
					$data = array(
						'role_id' => $role_id,
						'module'  => $module_id,
						'resource'=> $extra_resource_item,
					);
					$roles_res_extra_table->insert($data);
				}
			}
			$this->view->success = $this->_T("Resources updated.");
		}

		$db_roles_resources = $roles_resources_table->fetchAll('role_id = ' . $role_id );

		$resources = array();

		foreach ($db_roles_resources as $resource)
		{
			if (!array_key_exists($resource->module, $resources))
			{
				$resources[$resource->module] = array();
			}
			if (!array_key_exists($resource->controller, $resources[$resource->module]))
			{
				$resources[$resource->module][$resource->controller] = array();
			}
			$resources[$resource->module][$resource->controller][] = $resource->action;
		}

		/*
		* This is a poor man's introspector. The reflection API needs the classes actually available,
		* which creates naming conflicts between modules. What I do instead is read the physical files,
		* line by line, find the lines with "function fooAction" and determine that the action name is
		* "foo". It's a hack, but it works.
		*/

		$all_actions = array();
		$modules = array();
		$controllerdirs = array();

		$enabled_modules = $modules_table->getEnabledModules();

		foreach ($enabled_modules as $enabled_module)
		{
			$module_dir = 'modules';
			if ($enabled_module == 'default') $module_dir = 'core';
			$controllerdirs[$enabled_module] = Zend_Registry::get("basepath") . DIRECTORY_SEPARATOR . $module_dir . DIRECTORY_SEPARATOR . $enabled_module . DIRECTORY_SEPARATOR . "controllers";
		}

		$controllerdir = $controllerdirs[$module_id];

		$d = dir($controllerdir);
		$modules[] = $module_id;

		while (($entry = $d->read()) !== false)
		{
			if ($entry != '.' and $entry != '..' and $entry != '.svn')
			{
				$controller_name = substr($entry, 0, stripos($entry, 'Controller.php'));
				if ($module_id != "default" && substr($controller_name, 0, 1) == "_")
				{
					$controller_name = substr($controller_name, stripos($controller_name, '_') + 1);
				}
				$lines = file($controllerdir . DIRECTORY_SEPARATOR . $entry);
				foreach ($lines as $line)
				{
					if (preg_match('/function.*Action.*\(.*\).*\{?/', $line))
					{
						$action_name = trim(preg_replace('/Action.*/', '', preg_replace('/^.*function/', '', $line)));

						$allowed = false;
						if (array_key_exists($module_id, $resources))
						{
							if (array_key_exists($controller_name, $resources[$module_id]))
							{
								if (in_array($action_name, $resources[$module_id][$controller_name]))
								{
									$allowed = true;
								}
							}
						}
						$inherited = false;
						if (count($roles_table->getInheritedRoles($role_id)) > 0)
						{
							$inherited = $this->isResourceInherited($module_id, $controller_name, $action_name, $role_id);
						}
						$all_actions[$module_id][$controller_name][$action_name] = array(
							'allowed' => $allowed,
							'inherited' => $inherited,
						);
					}
				}
			}
		}

		$d->close();
		$this->view->modid = $module_id;

		if ($module_id == 'default') $mod_cfg = $modules_table_core->parseIni($module_id);
		else $mod_cfg = $modules_table->parseIni($module_id);

		$this->view->module_title = $mod_cfg['general']['name'];
		$this->view->actions = $all_actions;
		$this->view->modules = $enabled_modules;

		// get "extra" resources
		$extra_resources = array();
		if (array_key_exists('resources', $mod_cfg))
		{
			foreach ($mod_cfg['resources'] as $resource_name => $nicename)
			{
				$extra_resources[$resource_name]['nicename'] = $nicename;
				$extra_resources[$resource_name]['inherited'] = $this->isExtraResourceInherited($module_id, $resource_name, $role_id);
				$extra_resources[$resource_name]['allowed'] = $roles_res_extra_table->isAllowed($role_id, $module_id, $resource_name);
			}
		}
		$this->view->extra_resources = $extra_resources;

		$this->view->breadcrumbs = array(
			'Roles' => '/default/role/index',
			$role['shortname'] => '/default/role/edit/id/' . $role['id'],
			'Resources' => null,
		);
	}
Ejemplo n.º 5
0
 function indexAction()
 {
     $modules_table = new Modules("nuts");
     $request = new Bolts_Request($this->getRequest());
     if ($request->has("id") and $request->has("perform")) {
         switch ($request->perform) {
             case "enable":
                 if (!$modules_table->isEnabled($request->id)) {
                     if ($modules_table->enable($request->id)) {
                         if (!is_null($modules_table->success)) {
                             $this->view->success = $modules_table->success;
                         } else {
                             $this->view->success = "Module \"" . $request->id . "\" enabled.";
                         }
                     }
                 } else {
                     $this->view->notice = "Module \"" . $request->id . "\" is already enabled.";
                 }
                 break;
             case "disable":
                 if ($modules_table->isEnabled($request->id)) {
                     if ($modules_table->disable($request->id)) {
                         if (!is_null($modules_table->success)) {
                             $this->view->success = $modules_table->success;
                         } else {
                             $this->view->success = "Module \"" . $request->id . "\" disabled.";
                         }
                     }
                 } else {
                     $this->view->notice = "Module \"" . $request->id . "\" is already disabled.";
                 }
                 break;
             case "install":
                 if (!$modules_table->exists($request->id)) {
                     if ($modules_table->install($request->id)) {
                         if (!is_null($modules_table->success)) {
                             $this->view->success = $modules_table->success;
                         } else {
                             $this->view->success = "Module \"" . $request->id . "\" installed.";
                         }
                     }
                 } else {
                     $this->view->notice = "Module \"" . $request->id . "\" is already installed.";
                 }
                 break;
             case "uninstall":
                 if ($modules_table->exists($request->id)) {
                     if ($modules_table->disable($request->id)) {
                         if ($modules_table->uninstall($request->id)) {
                             if (!is_null($modules_table->success)) {
                                 $this->view->success = $modules_table->success;
                             } else {
                                 $this->view->success = "Module \"" . $request->id . "\" disabled and uninstalled.";
                             }
                         }
                     }
                 } else {
                     $this->view->notice = "Module \"" . $request->id . "\" is not installed.";
                 }
                 break;
         }
         if (count($modules_table->errors) > 0) {
             $this->view->errors = $modules_table->errors;
         }
         if (!is_null($modules_table->notice)) {
             $this->view->notice = $modules_table->notice;
         }
     }
     $basepath = Zend_Registry::get('basepath');
     $module_dir = $basepath . "/nuts";
     $o_module_dir = dir($module_dir);
     $available_modules = array();
     while (false !== ($entry = $o_module_dir->read())) {
         if (substr($entry, 0, 1) != ".") {
             if ($entry != "default") {
                 $full_dir = $module_dir . "/" . $entry;
                 if (file_exists($full_dir . "/module.ini") and !$modules_table->exists($entry)) {
                     $tmp_module = $modules_table->parseIni($entry);
                     $tmp_module['id'] = $entry;
                     $tmp_module['available'] = true;
                     $available_modules[] = $tmp_module;
                 }
             }
         }
     }
     $o_module_dir->close();
     $tmp_modules = array();
     $modules = $modules_table->fetchAll(null, "id");
     if (count($modules) > 0) {
         $tmp_modules = array();
         foreach ($modules as $module) {
             $module = $module->toArray();
             try {
                 $config = $modules_table->parseIni($module['id']);
                 foreach ($config as $key => $val) {
                     $module[$key] = $val;
                 }
                 $module['available'] = false;
                 $tmp_modules[] = $module;
             } catch (Exception $e) {
                 Bolts_Log::report("Could not set up " . $module, $e, Zend_Log::ERR);
             }
         }
     }
     $this->view->modules = array_merge($tmp_modules, $available_modules);
 }