/** * Create an object, it's table, files and rights * * @since 2.1.5 * @param name object short name * @param itemtype object class name * @param options create options : * - add_table : add the object table (default is no) * - create_default_profile : add default right (default is no) for current user profile * - add_injection_file : add file to integrate itemtype into the datainjection plugin * - add_language_file : create a default language for the itemtype * @return none */ static function addNewObject($name, $itemtype, $options = array()) { $params['add_table'] = false; $params['create_default_profile'] = false; $params['add_injection_file'] = false; $params['add_language_file'] = true; foreach ($options as $key => $value) { $params[$key] = $value; } if ($params['add_table']) { self::addTable($itemtype); } //Write object class on the filesystem self::addClassFile($name, $itemtype); //Write the form on the filesystem self::addFormFile($name, $itemtype); self::addSearchFile($name, $itemtype); //Add language file if ($params['add_injection_file']) { self::addLocales($name, $itemtype); } //Add file needed by datainjectin plugin if ($params['add_injection_file']) { self::addDatainjectionFile($name); } if ($params['create_default_profile']) { //Create rights for this new object PluginGenericobjectProfile::createAccess($_SESSION["glpiactiveprofile"]["id"], true); //Reload profiles PluginGenericobjectProfile::changeProfile(); } }
You should have received a copy of the GNU General Public License along with Genericobject. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- @package genericobject @author the genericobject plugin team @copyright Copyright (c) 2010-2011 Order plugin team @license GPLv2+ http://www.gnu.org/licenses/gpl.txt @link https://forge.indepnet.net/projects/genericobject @link http://www.glpi-project.org/ @since 2009 ---------------------------------------------------------------------- */ include ("../../../inc/includes.php"); if (isset($_GET['itemtype'])) { $itemtype = $_GET['itemtype']; $types = PluginGenericobjectType::getTypes(); // $type = new PluginGenericobjectType(); // $type->getFromDBByType($_GET['itemtype']); // Html::redirect(Toolbox::getItemTypeFormURL('PluginGenericobjectType').'?id='.$type->getID()); Session::checkRight(PluginGenericobjectProfile::getProfileNameForItemtype($itemtype), READ); Html::header(__("Type of objects", "genericobject"), $_SERVER['PHP_SELF'], "assets", $_GET['itemtype']); Search::Show($_GET['itemtype']); } Html::footer();
function plugin_genericobject_install() { global $DB; //check directories rights if (!check_directories()) { return false; } $migration = new Migration('2.1.0'); foreach (array('PluginGenericobjectField', 'PluginGenericobjectType', 'PluginGenericobjectProfile', 'PluginGenericobjectTypeFamily') as $itemtype) { if ($plug = isPluginItemType($itemtype)) { $plugname = strtolower($plug['plugin']); $dir = GLPI_ROOT . "/plugins/{$plugname}/inc/"; $item = strtolower($plug['class']); if (file_exists("{$dir}{$item}.class.php")) { include_once "{$dir}{$item}.class.php"; $itemtype::install($migration); } } } if (!is_dir(GENERICOBJECT_CLASS_PATH)) { @mkdir(GENERICOBJECT_CLASS_PATH, 0777, true) or die("Can't create folder " . GENERICOBJECT_CLASS_PATH); } //Init plugin & types plugin_init_genericobject(); //Init profiles PluginGenericobjectProfile::changeProfile(); return true; }
function plugin_genericobject_haveRight($class, $right) { $right_name = PluginGenericobjectProfile::getProfileNameForItemtype($class); return Session::haveRight($right_name, $right); }
function plugin_genericobject_install() { global $DB; include_once GLPI_ROOT . "/plugins/genericobject/inc/object.class.php"; include_once GLPI_ROOT . "/plugins/genericobject/inc/type.class.php"; $migration = new Migration('2.4.0'); foreach (array('PluginGenericobjectField', 'PluginGenericobjectCommonDropdown', 'PluginGenericobjectCommonTreeDropdown', 'PluginGenericobjectProfile', 'PluginGenericobjectType', 'PluginGenericobjectTypeFamily') as $itemtype) { if ($plug = isPluginItemType($itemtype)) { $plugname = strtolower($plug['plugin']); $dir = GLPI_ROOT . "/plugins/{$plugname}/inc/"; $item = strtolower($plug['class']); if (file_exists("{$dir}{$item}.class.php")) { include_once "{$dir}{$item}.class.php"; if (method_exists($itemtype, 'install')) { $itemtype::install($migration); } } } } if (!is_dir(GENERICOBJECT_CLASS_PATH)) { @mkdir(GENERICOBJECT_CLASS_PATH, 0777, true) or die("Can't create folder " . GENERICOBJECT_CLASS_PATH); } //Init plugin & types plugin_init_genericobject(); //Init profiles PluginGenericobjectProfile::changeProfile(); return true; }
/** * Display object preview form * @param type the object type */ static function showPrevisualisationForm(PluginGenericobjectType $type) { //Toolbox::logDebug(print_r($type->fields,true)); $itemtype = $type->fields['itemtype']; $item = new $itemtype(); $right_name = PluginGenericobjectProfile::getProfileNameForItemtype( $itemtype ); if (Session::haveRight($right_name, READ)) { $item->showForm(-1, array(), true); } else { echo "<br><strong>" . __("You must configure rights to enable the preview", "genericobject") . "</strong><br>"; } }
static function getMenuContent() { $types = PluginGenericobjectType::getTypes(); foreach ($types as $type) { $itemtype = $type['itemtype']; $item = new $itemtype(); $itemtype_rightname = PluginGenericobjectProfile::getProfileNameForItemtype($itemtype); if (class_exists($itemtype) && Session::haveRight($itemtype_rightname, READ)) { $links = array(); $links['search'] = $itemtype::getSearchUrl(false); if ($item->canUseTemplate()) { $links['template'] = "/front/setup.templates.php?itemtype={$itemtype}&add=0"; if (Session::haveRight($itemtype_rightname, CREATE)) { $links['add'] = "/front/setup.templates.php?itemtype={$itemtype}&add=1"; } } else { if (Session::haveRight($itemtype_rightname, CREATE)) { $links['add'] = $itemtype::getFormUrl(false); } } // $menu[strtolower($itemtype)] = array('title' => $type['itemtype']::getMenuName(), // 'page' => $itemtype::getSearchUrl(false)); if ($type['plugin_genericobject_typefamilies_id'] > 0 && (!isset($_GET['itemtype']) || !preg_match("/itemtype=" . $_GET['itemtype'] . "/", $_GET['itemtype']))) { $family_id = $type['plugin_genericobject_typefamilies_id']; $name = Dropdown::getDropdownName("glpi_plugin_genericobject_typefamilies", $family_id, 0, false); $str_name = strtolower($name); $menu[$str_name]['title'] = Dropdown::getDropdownName("glpi_plugin_genericobject_typefamilies", $family_id); $menu[$str_name]['page'] = '/plugins/genericobject/front/familylist.php?id=' . $family_id; $menu[$str_name]['options'][strtolower($itemtype)] = array('title' => $type['itemtype']::getMenuName(), 'page' => $itemtype::getSearchUrl(false), 'links' => $links); } else { $menu[strtolower($itemtype)] = array('title' => $type['itemtype']::getMenuName(), 'page' => $itemtype::getSearchUrl(false), 'links' => $links); } } } $menu['is_multi_entries'] = true; return $menu; }
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Genericobject. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- @package genericobject @author the genericobject plugin team @copyright Copyright (c) 2010-2011 Order plugin team @license GPLv2+ http://www.gnu.org/licenses/gpl.txt @link https://forge.indepnet.net/projects/genericobject @link http://www.glpi-project.org/ @since 2009 ---------------------------------------------------------------------- */ include "../../../inc/includes.php"; Session::checkRight("profile", "r"); $prof = new PluginGenericobjectProfile(); /* save profile */ if (isset($_POST['update_user_profile'])) { $prof->saveProfileToDB($_POST); PluginGenericobjectProfile::changeProfile(); } elseif (isset($_POST['update_all_rights']) && isset($_POST['profiles'])) { foreach ($_POST['profiles'] as $id => $values) { $values['id'] = $id; $prof->update($values); } PluginGenericobjectProfile::changeProfile(); } Html::redirect($_SERVER['HTTP_REFERER']);
You should have received a copy of the GNU General Public License along with Genericobject. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- @package genericobject @author the genericobject plugin team @copyright Copyright (c) 2010-2011 Order plugin team @license GPLv2+ http://www.gnu.org/licenses/gpl.txt @link https://forge.indepnet.net/projects/genericobject @link http://www.glpi-project.org/ @since 2009 ---------------------------------------------------------------------- */ include "../../../inc/includes.php"; Session::checkRight("profile", UPDATE); _log($_POST); $prof = new Profile(); /* save profile */ if (isset($_POST['update_all_rights']) && isset($_POST['itemtype'])) { $profiles = array(); foreach ($_POST as $key => $val) { if (preg_match("/^profile_/", $key)) { $id = preg_replace("/^profile_/", "", $key); $profiles[$id] = array("id" => $id, "_" . PluginGenericobjectProfile::getProfileNameForItemtype($_POST['itemtype']) => $val); } } _log($profiles); foreach ($profiles as $profile_id => $input) { $prof->update($input); } } Html::redirect($_SERVER['HTTP_REFERER']);