static function showForDocumentCategory($item)
 {
     $documentCategory = new self();
     if (!$documentCategory->getFromDBByQuery(" WHERE `documentcategories_id` = " . $item->fields['id'])) {
         $documentCategory->getEmpty();
     }
     echo "<form name='form' method='post' action='" . Toolbox::getItemTypeFormURL($documentCategory->getType()) . "'>";
     echo "<div align='center'><table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>" . __('Document category prefix', 'order') . "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     // Dropdown group
     echo "<td>";
     echo __('Document category prefix', 'order');
     echo "</td>";
     echo "<td>";
     echo "<input type='text' name='documentcategories_prefix' value='" . $documentCategory->fields['documentcategories_prefix'] . "'>";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td class='tab_bg_2 center' colspan='6'>";
     echo "<input type='submit' name='update' class='submit' value='" . _sx('button', 'Save') . "' >";
     echo "<input type='hidden' name='documentcategories_id' class='submit' value='" . $item->fields['id'] . "' >";
     echo "</td>";
     echo "</tr>";
     echo "</table></div>";
     Html::closeForm();
 }
Example #2
0
 /**
  * Pre update consumable
  * 
  * @param ConsumableItem $consumableItem
  */
 static function preUpdateConsumable(ConsumableItem $consumableItem)
 {
     $field = new self();
     $field->getFromDBByQuery(" WHERE `consumables_id` = '" . $consumableItem->input['id'] . "'");
     if (!empty($field->fields)) {
         $field->update(array('id' => $field->fields['id'], 'order_ref' => $consumableItem->input['order_ref']));
     } else {
         self::postAddConsumable($consumableItem);
     }
 }
Example #3
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case "use_filter_assign_group":
             $escalade_user = new self();
             $input = $ma->getInput();
             foreach ($ids as $id) {
                 if ($escalade_user->getFromDBByQuery("WHERE users_id = {$id}")) {
                     $escalade_user->fields['use_filter_assign_group'] = $input['use_filter_assign_group'];
                     if ($escalade_user->update($escalade_user->fields)) {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                     }
                 }
             }
     }
 }
Example #4
0
 /**
  * Update the rights of a profile (static since 0.90.1)
  *
  * @param $profiles_id
  * @param $rights         array
  */
 public static function updateProfileRights($profiles_id, array $rights = array())
 {
     $me = new self();
     foreach ($rights as $name => $right) {
         if (isset($right)) {
             if ($me->getFromDBByQuery("WHERE `profiles_id` = '{$profiles_id}'\n                                             AND `name` = '{$name}'")) {
                 $input = array('id' => $me->getID(), 'rights' => $right);
                 $me->update($input);
             } else {
                 $input = array('profiles_id' => $profiles_id, 'name' => $name, 'rights' => $right);
                 $me->add($input);
             }
         }
     }
     // Don't forget to complete the profile rights ...
     self::fillProfileRights($profiles_id);
 }
 static function addFileInRepo($params)
 {
     $deployFile = new self();
     $filename = addslashes($params['filename']);
     $file_tmp_name = $params['file_tmp_name'];
     $maxPartSize = 1024 * 1024;
     $repoPath = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/repository/";
     $tmpFilepart = tempnam(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/", "filestore");
     $sha512 = hash_file('sha512', $file_tmp_name);
     $short_sha512 = substr($sha512, 0, 6);
     $file_present_in_repo = FALSE;
     if ($deployFile->checkPresenceFile($sha512)) {
         $file_present_in_repo = TRUE;
     }
     $file_present_in_db = $deployFile->getFromDBByQuery("WHERE shortsha512 = '" . $short_sha512 . "'");
     //Manifest files contains the multiparts list attached to the file
     $manifest_path = GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/";
     $manifest_filename = $manifest_path . $sha512;
     $new_entry = array('name' => $filename, 'p2p' => $params['p2p'], 'p2p-retention-duration' => $params['p2p-retention-duration'], 'uncompress' => $params['uncompress']);
     $fdIn = fopen($file_tmp_name, 'rb');
     if (!$fdIn) {
         return FALSE;
     }
     $fdPart = NULL;
     $multiparts = array();
     do {
         clearstatcache();
         if (file_exists($tmpFilepart)) {
             if (feof($fdIn) || filesize($tmpFilepart) >= $maxPartSize) {
                 $part_sha512 = $deployFile->registerFilepart($repoPath, $tmpFilepart, $file_present_in_repo);
                 unlink($tmpFilepart);
                 $multiparts[] = $part_sha512;
             }
         }
         if (feof($fdIn)) {
             break;
         }
         $data = fread($fdIn, 1024 * 1024);
         $fdPart = gzopen($tmpFilepart, 'a');
         gzwrite($fdPart, $data, strlen($data));
         gzclose($fdPart);
     } while (1);
     //      $new_entry['multiparts'] = $multiparts;
     //create manifest file
     if (!$file_present_in_repo) {
         $handle = fopen($manifest_filename, "w+");
         if ($handle) {
             foreach ($multiparts as $sha) {
                 fwrite($handle, $sha . "\n");
             }
             fclose($handle);
         }
     }
     //TODO: Add a new files interface to list, create, manage entities and visibility
     // entity on a file is just anticipated and will be fully used later
     if (!$file_present_in_db) {
         $entry = array("name" => $filename, "filesize" => $params['filesize'], "mimetype" => $params['mime_type'], "sha512" => $sha512, "shortsha512" => $short_sha512, "comments" => "", "date_mod" => date('Y-m-d H:i:s'), "entities_id" => 0, "is_recursive" => 1);
         $deployFile->add($entry);
     }
     //get current order json
     $datas = json_decode(PluginFusioninventoryDeployOrder::getJson($params['orders_id']), TRUE);
     //add new entry
     $datas['associatedFiles'][$sha512] = $new_entry;
     if (!in_array($sha512, $datas['jobs']['associatedFiles'])) {
         $datas['jobs']['associatedFiles'][] = $sha512;
     }
     //update order
     PluginFusioninventoryDeployOrder::updateOrderJson($params['orders_id'], $datas);
     return TRUE;
 }
Example #6
0
 /**
  * Check zombie crontask
  *
  * @param $task for log
  **/
 static function cronWatcher($task)
 {
     global $CFG_GLPI, $DB;
     $cron_status = 0;
     // Crontasks running for more than 1 hour or 2 frequency
     $query = "SELECT *\n                FROM `glpi_crontasks`\n                WHERE `state` = '" . self::STATE_RUNNING . "'\n                      AND ((unix_timestamp(`lastrun`) + 2 * `frequency` < unix_timestamp(now()))\n                           OR (unix_timestamp(`lastrun`) + 2*" . HOUR_TIMESTAMP . " < unix_timestamp(now())))";
     $crontasks = array();
     foreach ($DB->request($query) as $data) {
         $crontasks[$data['id']] = $data;
     }
     if (count($crontasks)) {
         $task = new self();
         $task->getFromDBByQuery("WHERE `itemtype` = 'Crontask' AND `name` = 'watcher'");
         if (NotificationEvent::raiseEvent("alert", $task, array('items' => $crontasks))) {
             $cron_status = 1;
             $task->addVolume(1);
         }
         QueuedMail::forceSendFor($task->getType(), $task->fields['id']);
     }
     return 1;
 }
 /**
  * Delete config entries
  *
  * @since version 0.85
  *
  * @param $context string  context to get values (default for glpi is core)
  * @param $values  array   of config names to delete
  *
  * @return array of config values
  **/
 static function deleteConfigurationValues($context, array $values = array())
 {
     $config = new self();
     foreach ($values as $value) {
         if ($config->getFromDBByQuery("WHERE `context` = '{$context}'\n                                              AND `name` = '{$value}'")) {
             $config->delete(array('id' => $config->getID()));
         }
     }
 }