コード例 #1
0
ファイル: employee.class.php プロジェクト: geldarr/hack-space
 function showForm($plugin_resources_resources_id, $users_id, $withtemplate = '')
 {
     global $CFG_GLPI;
     if (!$this->canView()) {
         return false;
     }
     $employee_spotted = false;
     $resource = new PluginResourcesResource();
     $restrict = "`plugin_resources_resources_id` = '{$plugin_resources_resources_id}'";
     $employees = getAllDatasFromTable($this->getTable(), $restrict);
     $canedit = $resource->can($plugin_resources_resources_id, 'w');
     $ID = 0;
     if (!empty($employees)) {
         foreach ($employees as $employer) {
             $ID = $employer["id"];
         }
     }
     if (empty($ID)) {
         if ($this->getEmpty()) {
             $employee_spotted = true;
         }
     } else {
         if ($this->getfromDB($ID)) {
             $employee_spotted = true;
         }
     }
     if ($employee_spotted) {
         echo "<div align='center'>";
         if ($withtemplate < 2) {
             echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/resource.form.php\">";
         }
         if (!empty($plugin_resources_resources_id)) {
             $resource->getFromDB($plugin_resources_resources_id);
             $entity = $resource->fields["entities_id"];
         } else {
             $entity = $_SESSION["glpiactive_entity"];
         }
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='4'>" . self::getTypeName(1) . "</th></tr>";
         if (empty($plugin_resources_resources_id)) {
             echo "<tr class='tab_bg_1'><td colspan='4' class='center'>" . __('The resource is also created if not existent', 'resources');
             echo "</td></tr>";
         }
         echo "<tr class='tab_bg_1'><td colspan='2' class='center'>";
         echo "<input type='hidden' name='plugin_resources_resources_id' value='{$plugin_resources_resources_id}'>";
         echo PluginResourcesEmployer::getTypeName(1) . "</td>";
         echo "<td colspan='2'>";
         $params = array('name' => 'plugin_resources_employers_id', 'value' => $this->fields['plugin_resources_employers_id'], 'entity' => $entity, 'action' => $CFG_GLPI["root_doc"] . "/plugins/resources/ajax/dropdownLocation.php", 'span' => 'span_location');
         PluginResourcesResource::showGenericDropdown('PluginResourcesEmployer', $params);
         echo "</td></tr>";
         $locationId = 0;
         if ($this->fields["plugin_resources_employers_id"] > 0) {
             $employer = new PluginResourcesEmployer();
             $employer->getFromDB($this->fields["plugin_resources_employers_id"]);
             $locationId = $employer->fields["locations_id"];
         }
         echo "<tr class='tab_bg_1'><td colspan='2' class='center'>";
         _e('Address');
         echo "</td><td>";
         echo "<span id='span_location' name='span_location'>";
         if ($locationId > 0) {
             echo Dropdown::getDropdownName('glpi_locations', $locationId);
         } else {
             _e('None');
         }
         echo "</span>";
         echo "</td>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'><td colspan='2' class='center'>";
         echo PluginResourcesClient::getTypeName(1) . "</td>";
         echo "<td colspan='2'>";
         Dropdown::show('PluginResourcesClient', array('value' => $this->fields["plugin_resources_clients_id"], 'entity' => $entity));
         echo "</td></tr>";
         echo "<tr>";
         echo "<td class='tab_bg_2 top' colspan='4'>";
         if ($withtemplate < 2) {
             if (empty($ID)) {
                 if ($this->canCreate() && $canedit) {
                     echo "<input type='hidden' name='plugin_resources_resources_id' value=\"" . $plugin_resources_resources_id . "\">";
                     if (!empty($plugin_resources_resources_id)) {
                         echo "<div align='center'>";
                         echo "<input type='submit' name='addemployee' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
                         echo "</div>";
                     } else {
                         echo "<div align='center'>";
                         $resource->dropdownTemplate("templates_id", $_SESSION["glpiactive_entity"]);
                         echo "<input type='hidden' name='users_id' value='{$users_id}'>";
                         echo "&nbsp;<input type='submit' name='addressourceandemployee' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
                         echo "</div>";
                     }
                 }
             } else {
                 if ($this->canCreate() && $canedit) {
                     echo "<input type='hidden' name='id' value=\"{$ID}\">";
                     echo "<input type='hidden' name='plugin_resources_resources_id' value=\"" . $this->fields["plugin_resources_resources_id"] . "\">";
                     echo "<div align='center'>";
                     echo "<input type='submit' name='updateemployee' value=\"" . _sx('button', 'Update') . "\" class='submit' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                     echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='deleteemployee' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit'>";
                     echo "</div>";
                 }
             }
         }
         echo "</td>";
         echo "</tr>";
         echo "</table>";
         if ($withtemplate < 2) {
             Html::closeForm();
         }
         echo "</div>";
     }
 }