static function createFirstAccess($ID)
 {
     $profileRight = new ProfileRight();
     $currentRights = ProfileRight::getProfileRights($ID, array(self::RIGHT_SIMCARD_SIMCARD));
     $firstAccessRights = array_merge($currentRights, array(self::RIGHT_SIMCARD_SIMCARD => ALLSTANDARDRIGHT, self::RIGHT_SIMCARD_OPEN_TICKET => 1));
     $profileRight->updateProfileRights($ID, $firstAccessRights);
     //Add right to the current session
     $_SESSION['glpiactiveprofile'][self::RIGHT_SIMCARD_SIMCARD] = $firstAccessRights[self::RIGHT_SIMCARD_SIMCARD];
 }
Пример #2
0
 static function createFirstAccess($ID)
 {
     $profileRight = new ProfileRight();
     $currentRights = ProfileRight::getProfileRights($ID, array(self::RIGHT_SIMCARD_SIMCARD));
     $firstAccessRights = array_merge($currentRights, array(self::RIGHT_SIMCARD_SIMCARD => ALLSTANDARDRIGHT + self::SIMCARD_ASSOCIATE_TICKET + READNOTE + UPDATENOTE));
     $profileRight->updateProfileRights($ID, $firstAccessRights);
     //Add right to the current session
     $_SESSION['glpiactiveprofile'][self::RIGHT_SIMCARD_SIMCARD] = $firstAccessRights[self::RIGHT_SIMCARD_SIMCARD];
     $_SESSION['glpiactiveprofile']['helpdesk_item_type'][] = 'PluginSimcardSimcard';
 }
 /**
  * if profile cloned
  *
  * @param $prof   Profile  object
  **/
 static function cloneProfile(Profile $prof)
 {
     global $DB;
     ///TODO check if needed, as core should already do this.
     $profile_right = new ProfileRight();
     $crit = array('profiles_id' => $prof->input['_old_id'], "`name` LIKE 'plugin_reports_%'");
     $rights = array();
     foreach ($DB->request($profile_right->getTable(), $crit) as $data) {
         $rights[$data['name']] = $data['rights'];
     }
     unset($input['id']);
     $profile_right->updateProfileRights($prof->getID(), $rights);
 }
Пример #4
0
 /**
  * Create rights for the profile if it doesn't exists
  * @param profileID the profile ID
  * @return nothing
  */
 public static function createAccess($profiles_id, $itemtype, $first = false)
 {
     $rights = getAllDatasFromTable('glpi_profiles');
     $profile_right = new ProfileRight();
     $itemtype_rightname = self::getProfileNameForItemtype($itemtype);
     foreach ($rights as $right) {
         if ($right['id'] == $profiles_id) {
             $r = ALLSTANDARDRIGHT | READNOTE | UPDATENOTE;
         } else {
             $r = 0;
         }
         $profile_right->updateProfileRights($right['id'], array($itemtype_rightname => $r));
     }
 }
Пример #5
0
 function post_addItem()
 {
     global $DB;
     $rights = ProfileRight::getAllPossibleRights();
     ProfileRight::updateProfileRights($this->fields['id'], $rights);
     unset($this->profileRight);
     if (isset($this->fields['is_default']) && $this->fields["is_default"] == 1) {
         $query = "UPDATE " . $this->getTable() . "\n                   SET `is_default` = '0'\n                   WHERE `id` <> '" . $this->fields['id'] . "'";
         $DB->query($query);
     }
 }
Пример #6
0
/**
 * Update from 0.90.1 to 0.91
 *
 * @return bool for success (will die for most error)
**/
function update0901to091()
{
    global $DB, $migration, $CFG_GLPI;
    $updateresult = true;
    $ADDTODISPLAYPREF = array();
    //TRANS: %s is the number of new version
    $migration->displayTitle(sprintf(__('Update to %s'), '0.91'));
    $migration->setVersion('0.91');
    $backup_tables = false;
    $newtables = array('glpi_objectlocks');
    foreach ($newtables as $new_table) {
        // rename new tables if exists ?
        if (TableExists($new_table)) {
            $migration->dropTable("backup_{$new_table}");
            $migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
            $backup_tables = true;
            $query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
        }
    }
    if ($backup_tables) {
        $migration->displayWarning("You can delete backup tables if you have no need of them.", true);
    }
    $migration->displayMessage(sprintf(__('Add of - %s to database'), 'Object Locks'));
    // create table
    if (!TableExists('glpi_objectlocks')) {
        $query = "CREATE TABLE `glpi_objectlocks` (\n                 `id` INT(11) NOT NULL AUTO_INCREMENT,\n                 `itemtype` VARCHAR(100) NOT NULL COMMENT 'Type of locked object',\n                 `items_id` INT(11) NOT NULL COMMENT 'RELATION to various tables, according to itemtype (ID)',\n                 `users_id` INT(11) NOT NULL COMMENT 'id of the locker',\n                 `date_mod` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Timestamp of the lock',\n                 PRIMARY KEY (`id`),\n                 UNIQUE INDEX `item` (`itemtype`, `items_id`)\n               ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.91 add table glpi_objectlocks");
    }
    // insert new profile
    $query = "INSERT INTO `glpi_profiles`\n                    (`name`, `interface`, `is_default`, `helpdesk_hardware`, `helpdesk_item_type`,\n                     `ticket_status`, `date_mod`, `comment`, `problem_status`,\n                     `create_ticket_on_login`, `tickettemplates_id`, `change_status`)\n             VALUES\n                    ('Read-Only','central','0','0','[]',\n                     '{\"1\":{\"2\":0,\"3\":0,\"4\":0,\"5\":0,\"6\":0},\n                       \"2\":{\"1\":0,\"3\":0,\"4\":0,\"5\":0,\"6\":0},\n                       \"3\":{\"1\":0,\"2\":0,\"4\":0,\"5\":0,\"6\":0},\n                       \"4\":{\"1\":0,\"2\":0,\"3\":0,\"5\":0,\"6\":0},\n                       \"5\":{\"1\":0,\"2\":0,\"3\":0,\"4\":0,\"6\":0},\n                       \"6\":{\"1\":0,\"2\":0,\"3\":0,\"4\":0,\"5\":0}}',\n                     NULL,\n                     'This profile defines read-only access. It is used when objects are locked. It can also be used to give to users rights to unlock objects.',\n                    '{\"1\":{\"7\":0,\"2\":0,\"3\":0,\"4\":0,\"5\":0,\"8\":0,\"6\":0},\n                      \"7\":{\"1\":0,\"2\":0,\"3\":0,\"4\":0,\"5\":0,\"8\":0,\"6\":0},\n                      \"2\":{\"1\":0,\"7\":0,\"3\":0,\"4\":0,\"5\":0,\"8\":0,\"6\":0},\n                      \"3\":{\"1\":0,\"7\":0,\"2\":0,\"4\":0,\"5\":0,\"8\":0,\"6\":0},\n                      \"4\":{\"1\":0,\"7\":0,\"2\":0,\"3\":0,\"5\":0,\"8\":0,\"6\":0},\n                      \"5\":{\"1\":0,\"7\":0,\"2\":0,\"3\":0,\"4\":0,\"8\":0,\"6\":0},\n                      \"8\":{\"1\":0,\"7\":0,\"2\":0,\"3\":0,\"4\":0,\"5\":0,\"6\":0},\n                      \"6\":{\"1\":0,\"7\":0,\"2\":0,\"3\":0,\"4\":0,\"5\":0,\"8\":0}}',\n                     0, 0,\n                     '{\"1\":{\"9\":0,\"10\":0,\"7\":0,\"4\":0,\"11\":0,\"12\":0,\"5\":0,\"8\":0,\"6\":0},\n                       \"9\":{\"1\":0,\"10\":0,\"7\":0,\"4\":0,\"11\":0,\"12\":0,\"5\":0,\"8\":0,\"6\":0},\n                       \"10\":{\"1\":0,\"9\":0,\"7\":0,\"4\":0,\"11\":0,\"12\":0,\"5\":0,\"8\":0,\"6\":0},\n                       \"7\":{\"1\":0,\"9\":0,\"10\":0,\"4\":0,\"11\":0,\"12\":0,\"5\":0,\"8\":0,\"6\":0},\n                       \"4\":{\"1\":0,\"9\":0,\"10\":0,\"7\":0,\"11\":0,\"12\":0,\"5\":0,\"8\":0,\"6\":0},\n                       \"11\":{\"1\":0,\"9\":0,\"10\":0,\"7\":0,\"4\":0,\"12\":0,\"5\":0,\"8\":0,\"6\":0},\n                       \"12\":{\"1\":0,\"9\":0,\"10\":0,\"7\":0,\"4\":0,\"11\":0,\"5\":0,\"8\":0,\"6\":0},\n                       \"5\":{\"1\":0,\"9\":0,\"10\":0,\"7\":0,\"4\":0,\"11\":0,\"12\":0,\"8\":0,\"6\":0},\n                       \"8\":{\"1\":0,\"9\":0,\"10\":0,\"7\":0,\"4\":0,\"11\":0,\"12\":0,\"5\":0,\"6\":0},\n                       \"6\":{\"1\":0,\"9\":0,\"10\":0,\"7\":0,\"4\":0,\"11\":0,\"12\":0,\"5\":0,\"8\":0}}')";
    $DB->queryOrDie($query, "0.91 update profile with Unlock profile");
    $ret = $DB->insert_id();
    // insert default rights for this profile
    ProfileRight::updateProfileRights($ret, array('backup' => '1', 'bookmark_public' => '1', 'budget' => '161', 'calendar' => '1', 'cartridge' => '161', 'change' => '1185', 'changevalidation' => '0', 'computer' => '161', 'config' => '1', 'consumable' => '161', 'contact_enterprise' => '161', 'contract' => '161', 'device' => '0', 'document' => '161', 'domain' => '1', 'dropdown' => '1', 'entity' => '1185', 'followup' => '8193', 'global_validation' => '0', 'group' => '129', 'infocom' => '1', 'internet' => '129', 'itilcategory' => '1', 'knowbase' => '2177', 'knowbasecategory' => '1', 'link' => '129', 'location' => '1', 'logs' => '1', 'monitor' => '161', 'netpoint' => '1', 'networking' => '161', 'notification' => '1', 'password_update' => '0', 'peripheral' => '161', 'phone' => '161', 'planning' => '3073', 'printer' => '161', 'problem' => '1185', 'profile' => '129', 'project' => '1185', 'projecttask' => '1', 'queuedmail' => '1', 'reminder_public' => '129', 'reports' => '1', 'reservation' => '1', 'rssfeed_public' => '129', 'rule_dictionnary_dropdown' => '1', 'rule_dictionnary_printer' => '1', 'rule_dictionnary_software' => '1', 'rule_import' => '1', 'rule_ldap' => '1', 'rule_mailcollector' => '1', 'rule_softwarecategories' => '1', 'rule_ticket' => '1', 'search_config' => '0', 'show_group_hardware' => '1', 'sla' => '1', 'software' => '161', 'solutiontemplate' => '1', 'state' => '1', 'statistic' => '1', 'task' => '8193', 'taskcategory' => '1', 'ticket' => '7297', 'ticketcost' => '1', 'ticketrecurrent' => '1', 'tickettemplate' => '1', 'ticketvalidation' => '0', 'transfer' => '1', 'typedoc' => '1', 'user' => '2177'));
    // updates rights for Super-Admin profile
    foreach ($CFG_GLPI['lock_lockable_objects'] as $itemtype) {
        $rightnames[] = "'" . $itemtype::$rightname . "'";
    }
    $query = "UPDATE `glpi_profilerights`\n             SET `rights` = `rights` | " . UNLOCK . "\n             WHERE `profiles_id` = '4'\n                   AND `name` IN (" . implode(",", $rightnames) . ")";
    $DB->queryOrDie($query, "update super-admin profile with UNLOCK right");
    Config::setConfigurationValues('core', array('lock_use_lock_item' => 0, 'lock_autolock_mode' => 1, 'lock_directunlock_notification' => 0, 'lock_item_list' => '[]', 'lock_lockprofile_id' => $ret));
    // cron task
    if (!countElementsInTable('glpi_crontasks', "`itemtype`='ObjectLock' AND `name`='unlockobject'")) {
        $query = "INSERT INTO `glpi_crontasks`\n                       (`itemtype`, `name`, `frequency`, `param`, `state`, `mode`, `allowmode`,\n                        `hourmin`, `hourmax`, `logs_lifetime`, `lastrun`, `lastcode`, `comment`)\n                VALUES ('ObjectLock', 'unlockobject', 86400, 4, 0, 1, 3,\n                        0, 24, 30, NULL, NULL, NULL); ";
        $DB->queryOrDie($query, "Update UnlockObject cron task");
    }
    // notification template
    $query = "SELECT *\n             FROM `glpi_notificationtemplates`\n             WHERE `itemtype` = 'ObjectLock'";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) == 0) {
            $query = "INSERT INTO `glpi_notificationtemplates`\n                          (`name`, `itemtype`, `date_mod`)\n                   VALUES ('Unlock Item request', 'ObjectLock', NOW())";
            $DB->queryOrDie($query, "0.84 add planning recall notification");
            $notid = $DB->insert_id();
            $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                (`notificationtemplates_id`, `language`,\n                                 `subject`,\n                                 `content_text`,\n                                 `content_html`)\n                         VALUES ({$notid}, '', '##objectlock.action##',\n      '##objectlock.type## ###objectlock.id## - ##objectlock.name##\n\n      ##lang.objectlock.url##\n      ##objectlock.url##\n\n      ##lang.objectlock.date_mod##\n      ##objectlock.date_mod##\n\n      Hello ##objectlock.lockedby.firstname##,\n      Could go to this item and unlock it for me?\n      Thank you,\n      Regards,\n      ##objectlock.requester.firstname##',\n      '&lt;table&gt;\n      &lt;tbody&gt;\n      &lt;tr&gt;&lt;th colspan=\"2\"&gt;&lt;a href=\"##objectlock.url##\"&gt;##objectlock.type## ###objectlock.id## - ##objectlock.name##&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;\n      &lt;tr&gt;\n      &lt;td&gt;##lang.objectlock.url##&lt;/td&gt;\n      &lt;td&gt;##objectlock.url##&lt;/td&gt;\n      &lt;/tr&gt;\n      &lt;tr&gt;\n      &lt;td&gt;##lang.objectlock.date_mod##&lt;/td&gt;\n      &lt;td&gt;##objectlock.date_mod##&lt;/td&gt;\n      &lt;/tr&gt;\n      &lt;/tbody&gt;\n      &lt;/table&gt;\n      &lt;p&gt;&lt;span style=\"font-size: small;\"&gt;Hello ##objectlock.lockedby.firstname##,&lt;br /&gt;Could go to this item and unlock it for me?&lt;br /&gt;Thank you,&lt;br /&gt;Regards,&lt;br /&gt;##objectlock.requester.firstname## ##objectlock.requester.lastname##&lt;/span&gt;&lt;/p&gt;')";
            $DB->queryOrDie($query, "0.91 add Unlock Request notification translation");
            $query = "INSERT INTO `glpi_notifications`\n                                (`name`, `entities_id`, `itemtype`, `event`, `mode`,\n                                 `notificationtemplates_id`, `comment`, `is_recursive`, `is_active`,\n                                 `date_mod`)\n                         VALUES ('Request Unlock Items', 0, 'ObjectLock', 'unlock', 'mail',\n                                   {$notid}, '', 1, 1, NOW())";
            $DB->queryOrDie($query, "0.91 add Unlock Request notification");
            $notifid = $DB->insert_id();
            $query = "INSERT INTO `glpi_notificationtargets`\n                                (`id`, `notifications_id`, `type`, `items_id`)\n                         VALUES (NULL, {$notifid}, " . Notification::USER_TYPE . ", " . Notification::USER . ");";
            $DB->queryOrDie($query, "0.91 add Unlock Request notification target");
        }
    }
    Config::setConfigurationValues('core', array('set_default_requester' => 1));
    $migration->addField("glpi_users", "set_default_requester", "tinyint(1) NULL DEFAULT NULL");
    // Add task template
    if (!TableExists('glpi_tasktemplates')) {
        $query = "CREATE TABLE `glpi_tasktemplates` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `entities_id` int(11) NOT NULL DEFAULT '0',\n                  `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n                  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `content` text COLLATE utf8_unicode_ci,\n                  `taskcategories_id` int(11) NOT NULL DEFAULT '0',\n                  `actiontime` int(11) NOT NULL DEFAULT '0',\n                  `comment` text COLLATE utf8_unicode_ci,\n                  PRIMARY KEY (`id`),\n                  KEY `name` (`name`),\n                  KEY `is_recursive` (`is_recursive`),\n                  KEY `taskcategories_id` (`taskcategories_id`),\n                  KEY `entities_id` (`entities_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->queryOrDie($query, "0.84 add table glpi_tasktemplates");
    }
    $migration->addField("glpi_users", "lock_autolock_mode", "bool", true);
    $migration->addField("glpi_users", "lock_directunlock_notification", "bool", true);
    // ************ Keep it at the end **************
    $migration->executeMigration();
    return $updateresult;
}
Пример #7
0
 /**
  * @since 0.85
  * Migration rights from old system to the new one for one profile
  * @param $profiles_id the profile ID
  */
 static function migrateOneProfile($profiles_id)
 {
     global $DB;
     //Cannot launch migration if there's nothing to migrate...
     if (!TableExists('glpi_plugin_uninstall_profiles')) {
         return true;
     }
     foreach ($DB->request('glpi_plugin_uninstall_profiles', "`id`='{$profiles_id}'") as $profile_data) {
         $translatedRight = self::translateARight($profile_data["use"]);
         $translatedRight = $translatedRight | (self::translateARight($profile_data["replace"]) ? self::RIGHT_REPLACE : 0);
         ProfileRight::updateProfileRights($profiles_id, array(PluginUninstallProfile::$rightname => $translatedRight));
     }
 }
Пример #8
0
 /**
  * Create rights for the profile if it doesn't exists
  * @param profileID the profile ID
  * @return nothing
  */
 public static function createAccess($profiles_id, $itemtype, $first=false) {
    $profile_right = new ProfileRight();
    $itemtype_rightname = self::getProfileNameForItemtype($itemtype);
    $profile_right->updateProfileRights($profiles_id, array(
       $itemtype_rightname => ALLSTANDARDRIGHT
    ));
 }