entity.class.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  * @version $Id: entity.class.php 21382 2013-07-22 10:36:45Z tsmr $
00004  -------------------------------------------------------------------------
00005  GLPI - Gestionnaire Libre de Parc Informatique
00006  Copyright (C) 2003-2013 by the INDEPNET Development Team.
00007 
00008  http://indepnet.net/   http://glpi-project.org
00009  -------------------------------------------------------------------------
00010 
00011  LICENSE
00012 
00013  This file is part of GLPI.
00014 
00015  GLPI is free software; you can redistribute it and/or modify
00016  it under the terms of the GNU General Public License as published by
00017  the Free Software Foundation; either version 2 of the License, or
00018  (at your option) any later version.
00019 
00020  GLPI is distributed in the hope that it will be useful,
00021  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  GNU General Public License for more details.
00024 
00025  You should have received a copy of the GNU General Public License
00026  along with GLPI. If not, see <http://www.gnu.org/licenses/>.
00027  --------------------------------------------------------------------------
00028  */
00029 
00030 /** @file
00031 * @brief
00032 */
00033 
00034 if (!defined('GLPI_ROOT')) {
00035    die("Sorry. You can't access directly to this file");
00036 }
00037 
00038 /**
00039  * Entity class
00040  */
00041 class Entity extends CommonTreeDropdown {
00042 
00043    public $must_be_replace = true;
00044    public $dohistory       = true;
00045 
00046    public $first_level_menu  = "admin";
00047    public $second_level_menu = "entity";
00048 
00049    const CONFIG_PARENT   = -2;
00050    const CONFIG_NEVER    = -10;
00051 
00052    const AUTO_ASSIGN_HARDWARE_CATEGORY = 1;
00053    const AUTO_ASSIGN_CATEGORY_HARDWARE = 2;
00054 
00055    // Array of "right required to update" => array of fields allowed
00056    // Missing field here couldn't be update (no right)
00057    private static $field_right = array('entity'
00058                                           => array(// Address
00059                                                    'address', 'country', 'email', 'fax', 'notepad',
00060                                                    'phonenumber', 'postcode', 'state', 'town',
00061                                                    'website',
00062                                                    // Advanced (could be user_authtype ?)
00063                                                    'authldaps_id', 'entity_ldapfilter', 'ldap_dn',
00064                                                    'mail_domain', 'tag',
00065                                                    // Inventory
00066                                                    'autofill_buy_date', 'autofill_delivery_date',
00067                                                    'autofill_order_date', 'autofill_use_date',
00068                                                    'autofill_warranty_date',
00069                                                    'entities_id_software', 'level', 'name',
00070                                                    'completename', 'entities_id',
00071                                                    'ancestors_cache', 'sons_cache', 'comment'),
00072                                        // Notification
00073                                        'notification'
00074                                           => array('admin_email', 'admin_reply', 'admin_email_name',
00075                                                    'admin_reply_name',
00076                                                    'default_cartridges_alarm_threshold',
00077                                                    'default_consumables_alarm_threshold',
00078                                                    'default_contract_alert', 'default_infocom_alert',
00079                                                    'mailing_signature', 'cartridges_alert_repeat',
00080                                                    'consumables_alert_repeat', 'notclosed_delay',
00081                                                    'use_licenses_alert',
00082                                                    'send_licenses_alert_before_delay',
00083                                                    'use_contracts_alert',
00084                                                    'send_contracts_alert_before_delay',
00085                                                    'use_reservations_alert', 'use_infocoms_alert',
00086                                                    'send_infocoms_alert_before_delay',
00087                                                    'notification_subject_tag'),
00088                                        // Helpdesk
00089                                        'entity_helpdesk'
00090                                           => array('calendars_id', 'tickettype', 'auto_assign_mode',
00091                                                    'autoclose_delay', 'inquest_config',
00092                                                    'inquest_rate', 'inquest_delay', 'inquest_URL',
00093                                                    'max_closedate', 'tickettemplates_id'));
00094 
00095 
00096    function getForbiddenStandardMassiveAction() {
00097 
00098       $forbidden   = parent::getForbiddenStandardMassiveAction();
00099       $forbidden[] = 'delete';
00100       $forbidden[] = 'purge';
00101       $forbidden[] = 'restore';
00102       $forbidden[] = 'merge';
00103       return $forbidden;
00104    }
00105 
00106 
00107    /**
00108     * @since version 0.84
00109    **/
00110    function pre_deleteItem() {
00111 
00112       // Security do not delete root entity
00113       if ($this->input['id'] == 0) {
00114          return false;
00115       }
00116       return true;
00117    }
00118 
00119 
00120    static function getTypeName($nb=0) {
00121       return _n('Entity', 'Entities', $nb);
00122    }
00123 
00124 
00125    static function canCreate() {
00126       return Session::haveRight('entity', 'w');
00127    }
00128 
00129 
00130    static function canView() {
00131       return Session::haveRight('entity', 'r');
00132    }
00133 
00134 
00135    function canCreateItem() {
00136       // Check the parent
00137       return Session::haveRecursiveAccessToEntity($this->getField('entities_id'));
00138    }
00139 
00140 
00141    function canUpdateItem() {
00142       // Check the current entity
00143       return Session::haveAccessToEntity($this->getField('id'));
00144    }
00145 
00146 
00147    /**
00148     * @since version 0.84
00149     *
00150     * @see CommonDBTM::canViewItem()
00151    **/
00152    function canViewItem() {
00153       // Check the current entity
00154       return Session::haveAccessToEntity($this->getField('id'));
00155    }
00156 
00157 
00158    /**
00159     * @see CommonDBTM::isNewID()
00160    **/
00161    static function isNewID($ID) {
00162       return (($ID < 0) || !strlen($ID));
00163    }
00164 
00165 
00166    /**
00167     * Check right on each field before add / update
00168     *
00169     * @since version 0.84 (before in entitydata.class)
00170     *
00171     * @param $input array (form)
00172     *
00173     * @return array (filtered input)
00174    **/
00175    private function checkRightDatas($input) {
00176 
00177       $tmp = array();
00178 
00179       if (isset($input['id'])) {
00180          $tmp['id'] = $input['id'];
00181       }
00182 
00183       foreach (self::$field_right as $right => $fields) {
00184 
00185          if (Session::haveRight($right, 'w')) {
00186             foreach ($fields as $field) {
00187                if (isset($input[$field])) {
00188                   $tmp[$field] = $input[$field];
00189                }
00190             }
00191          }
00192       }
00193       // Add framework  / internal ones
00194       foreach ($input as $key => $val) {
00195          if ($key[0] == '_') {
00196             $tmp[$key] = $input[$key];
00197          }
00198       }
00199 
00200       return $tmp;
00201    }
00202 
00203 
00204    /**
00205     * @since version 0.84 (before in entitydata.class)
00206    **/
00207    function prepareInputForAdd($input) {
00208       global $DB;
00209 
00210       $input = parent::prepareInputForAdd($input);
00211 
00212       $query = "SELECT MAX(`id`)+1 AS newID
00213                 FROM `glpi_entities`";
00214       if ($result = $DB->query($query)) {
00215           $input['id'] = $DB->result($result,0,0);
00216       } else {
00217          return false;
00218       }
00219       $input['max_closedate'] = $_SESSION["glpi_currenttime"];
00220       return $this->checkRightDatas($input);
00221    }
00222 
00223 
00224    /**
00225     * @since version 0.84 (before in entitydata.class)
00226    **/
00227    function prepareInputForUpdate($input) {
00228 
00229       $input = parent::prepareInputForUpdate($input);
00230 
00231       // Si on change le taux de déclenchement de l'enquête (enquête activée) ou le type de l'enquete,
00232       // cela s'applique aux prochains tickets - Pas à l'historique
00233       if ((isset($input['inquest_rate'])
00234            && (($this->fields['inquest_rate'] == 0)
00235                || is_null($this->fields['max_closedate']))
00236            && ($input['inquest_rate'] != $this->fields['inquest_rate']))
00237           || (isset($input['inquest_config'])
00238               && (($this->fields['inquest_config'] == 0)
00239                   || is_null($this->fields['max_closedate']))
00240               && ($input['inquest_config'] != $this->fields['inquest_config']))) {
00241 
00242          $input['max_closedate'] = $_SESSION["glpi_currenttime"];
00243       }
00244 
00245       // Force entities_id = -1 for root entity
00246       if ($input['id'] == 0) {
00247          $input['entities_id'] = -1;
00248          $input['level']       = 1;
00249       }
00250       if (!Session::isCron()) { // Filter input for connected
00251          $input = $this->checkRightDatas($input);
00252       }
00253       return $input;
00254    }
00255 
00256 
00257    /**
00258     * @see CommonTreeDropdown::defineTabs()
00259    **/
00260    function defineTabs($options=array()) {
00261 
00262       $ong = array();
00263       $this->addStandardTab($this->getType(), $ong, $options);
00264       $this->addStandardTab('Profile_User',$ong, $options);
00265       $this->addStandardTab(__CLASS__, $ong, $options);
00266       $this->addStandardTab('Rule', $ong, $options);
00267       $this->addStandardTab('Document_Item',$ong, $options);
00268       $this->addStandardTab('Note',$ong, $options);
00269       $this->addStandardTab('Log',$ong, $options);
00270 
00271       return $ong;
00272    }
00273 
00274 
00275    /**
00276     * @since version 0.84 (before in entitydata.class)
00277    **/
00278    function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
00279 
00280       if (!$withtemplate) {
00281          switch ($item->getType()) {
00282             case __CLASS__ :
00283                $ong    = array();
00284                $ong[1] = $this->getTypeName(2);
00285                $ong[2] = __('Address');
00286                $ong[3] = __('Advanced information');
00287                if (Session::haveRight('notification','r')) {
00288                   $ong[4] = _n('Notification', 'Notifications',2);
00289                }
00290                if (Session::haveRight('entity_helpdesk','r')) {
00291                   $ong[5] = __('Assistance');
00292                }
00293                $ong[6] = __('Assets');
00294 
00295                return $ong;
00296          }
00297       }
00298       return '';
00299    }
00300 
00301 
00302    /**
00303     * @since version 0.84 (before in entitydata.class)
00304    **/
00305    static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
00306 
00307       if ($item->getType()==__CLASS__) {
00308          switch ($tabnum) {
00309             case 1 :
00310                $item->showChildren();
00311                break;
00312 
00313             case 2 :
00314                self::showStandardOptions($item);
00315                break;
00316 
00317             case 3 :
00318                self::showAdvancedOptions($item);
00319                break;
00320 
00321             case 4 :
00322                self::showNotificationOptions($item);
00323                break;
00324 
00325             case 5 :
00326                self::showHelpdeskOptions($item);
00327                break;
00328 
00329             case 6 :
00330                self::showInventoryOptions($item);
00331                break;
00332          }
00333       }
00334       return true;
00335    }
00336 
00337 
00338    /**
00339     * Print a good title for entity pages
00340     *
00341     *@return nothing (display)
00342     **/
00343    function title() {
00344       // Empty title for entities
00345    }
00346 
00347 
00348    function displayHeader() {
00349       Html::header($this->getTypeName(1), '', "admin", "entity");
00350    }
00351 
00352 
00353    /**
00354     * Get the ID of entity assigned to the object
00355     *
00356     * simply return ID
00357     *
00358     * @return ID of the entity
00359    **/
00360    function getEntityID() {
00361 
00362       if (isset($this->fields["id"])) {
00363          return $this->fields["id"];
00364       }
00365       return -1;
00366    }
00367 
00368 
00369    function isEntityAssign() {
00370       return true;
00371    }
00372 
00373 
00374    function maybeRecursive() {
00375       return true;
00376    }
00377 
00378 
00379    /**
00380     * Is the object recursive
00381     *
00382     * Entity are always recursive
00383     *
00384     * @return integer (0/1)
00385    **/
00386    function isRecursive () {
00387       return true;
00388    }
00389 
00390 
00391    function post_addItem() {
00392 
00393       parent::post_addItem();
00394 
00395       // Add right to current user - Hack to avoid login/logout
00396       $_SESSION['glpiactiveentities'][$this->fields['id']] = $this->fields['id'];
00397       $_SESSION['glpiactiveentities_string']              .= ",'".$this->fields['id']."'";
00398    }
00399 
00400 
00401    function cleanDBonPurge() {
00402       global $DB;
00403 
00404       // most use entities_id, RuleDictionnarySoftwareCollection use new_entities_id
00405       Rule::cleanForItemAction($this, '%entities_id');
00406       Rule::cleanForItemCriteria($this);
00407 
00408       $gki = new Entity_KnowbaseItem();
00409       $gki->cleanDBonItemDelete($this->getType(), $this->fields['id']);
00410 
00411       $gr = new Entity_Reminder();
00412       $gr->cleanDBonItemDelete($this->getType(), $this->fields['id']);
00413    }
00414 
00415 
00416    function getSearchOptions() {
00417       /// TODO lots of specific values may be passed to standard ones.
00418 
00419       $tab                     = array();
00420       $tab['common']           = __('Characteristics');
00421 
00422       $tab[1]['table']         = $this->getTable();
00423       $tab[1]['field']         = 'completename';
00424       $tab[1]['name']          = __('Complete name');
00425       $tab[1]['datatype']      = 'itemlink';
00426       $tab[1]['massiveaction'] = false;
00427 
00428       $tab[2]['table']         = $this->getTable();
00429       $tab[2]['field']         = 'id';
00430       $tab[2]['name']          = __('ID');
00431       $tab[2]['massiveaction'] = false;
00432       $tab[2]['datatype']      = 'number';
00433 
00434       $tab[3]['table']         = $this->getTable();
00435       $tab[3]['field']         = 'address';
00436       $tab[3]['name']          = __('Address');
00437       $tab[3]['massiveaction'] = false;
00438       $tab[3]['datatype']      = 'text';
00439 
00440       $tab[4]['table']         = $this->getTable();
00441       $tab[4]['field']         = 'website';
00442       $tab[4]['name']          = __('Website');
00443       $tab[4]['massiveaction'] = false;
00444       $tab[4]['datatype']      = 'string';
00445 
00446       $tab[5]['table']         = $this->getTable();
00447       $tab[5]['field']         = 'phonenumber';
00448       $tab[5]['name']          = __('Phone');
00449       $tab[5]['massiveaction'] = false;
00450       $tab[5]['datatype']      = 'string';
00451 
00452       $tab[6]['table']         = $this->getTable();
00453       $tab[6]['field']         = 'email';
00454       $tab[6]['name']          = _n('Email', 'Emails', 1);
00455       $tab[6]['datatype']      = 'email';
00456       $tab[6]['massiveaction'] = false;
00457 
00458       $tab[7]['table']         = $this->getTable();
00459       $tab[7]['field']         = 'ldap_dn';
00460       $tab[7]['name']          = __('LDAP directory information attribute representing the entity');
00461       $tab[7]['massiveaction'] = false;
00462       $tab[7]['datatype']      = 'string';
00463 
00464       $tab[8]['table']         = $this->getTable();
00465       $tab[8]['field']         = 'tag';
00466       $tab[8]['name']          = __('Information in inventory tool (TAG) representing the entity');
00467       $tab[8]['massiveaction'] = false;
00468       $tab[8]['datatype']      = 'string';
00469 
00470       $tab[9]['table']         = 'glpi_authldaps';
00471       $tab[9]['field']         = 'name';
00472       $tab[9]['name']          = __('LDAP directory of an entity');
00473       $tab[9]['massiveaction'] = false;
00474       $tab[9]['datatype']      = 'dropdown';
00475 
00476       $tab[10]['table']         = $this->getTable();
00477       $tab[10]['field']         = 'fax';
00478       $tab[10]['name']          = __('Fax');
00479       $tab[10]['massiveaction'] = false;
00480       $tab[10]['datatype']      = 'string';
00481 
00482       $tab[11]['table']         = $this->getTable();
00483       $tab[11]['field']         = 'town';
00484       $tab[11]['name']          = __('City');
00485       $tab[11]['massiveaction'] = false;
00486       $tab[11]['datatype']      = 'string';
00487 
00488       $tab[12]['table']         = $this->getTable();
00489       $tab[12]['field']         = 'state';
00490       $tab[12]['name']          = __('State');
00491       $tab[12]['massiveaction'] = false;
00492       $tab[12]['datatype']      = 'string';
00493 
00494       $tab[13]['table']         = $this->getTable();
00495       $tab[13]['field']         = 'country';
00496       $tab[13]['name']          = __('Country');
00497       $tab[13]['massiveaction'] = false;
00498       $tab[13]['datatype']      = 'string';
00499 
00500       $tab[14]['table']         = $this->getTable();
00501       $tab[14]['field']         = 'name';
00502       $tab[14]['name']          = __('Name');
00503       $tab[14]['datatype']      = 'itemlink';
00504       $tab[14]['massiveaction'] = false;
00505 
00506       $tab[16]['table']         = $this->getTable();
00507       $tab[16]['field']         = 'comment';
00508       $tab[16]['name']          = __('Comments');
00509       $tab[16]['datatype']      = 'text';
00510 
00511       $tab[17]['table']         = $this->getTable();
00512       $tab[17]['field']         = 'entity_ldapfilter';
00513       $tab[17]['name']          = __('Search filter (if needed)');
00514       $tab[17]['massiveaction'] = false;
00515       $tab[17]['datatype']      = 'string';
00516 
00517       $tab[18]['table']         = $this->getTable();
00518       $tab[18]['field']         = 'admin_email';
00519       $tab[18]['name']          = __('Administrator email');
00520       $tab[18]['massiveaction'] = false;
00521       $tab[18]['datatype']      = 'string';
00522 
00523       $tab[19]['table']         = $this->getTable();
00524       $tab[19]['field']         = 'admin_reply';
00525       $tab[19]['name']          = __('Administrator reply-to email (if needed)');
00526       $tab[19]['massiveaction'] = false;
00527       $tab[19]['datatype']      = 'string';
00528 
00529       $tab[20]['table']         = $this->getTable();
00530       $tab[20]['field']         = 'mail_domain';
00531       $tab[20]['name']          = __('Mail domain');
00532       $tab[20]['massiveaction'] = false;
00533       $tab[20]['datatype']      = 'string';
00534 
00535       $tab[21]['table']         = $this->getTable();
00536       $tab[21]['field']         = 'notification_subject_tag';
00537       $tab[21]['name']          = __('Prefix for notifications');
00538       $tab[21]['datatype']      = 'string';
00539 
00540       $tab[22]['table']         = $this->getTable();
00541       $tab[22]['field']         = 'admin_email_name';
00542       $tab[22]['name']          = __('Administrator name');
00543       $tab[22]['datatype']      = 'string';
00544 
00545       $tab[23]['table']         = $this->getTable();
00546       $tab[23]['field']         = 'admin_reply_name';
00547       $tab[23]['name']          = __('Response address (if needed)');
00548       $tab[23]['datatype']      = 'string';
00549 
00550       $tab[24]['table']         = $this->getTable();
00551       $tab[24]['field']         = 'mailing_signature';
00552       $tab[24]['name']          = __('Email signature');
00553       $tab[24]['datatype']      = 'text';
00554 
00555       $tab[25]['table']         = $this->getTable();
00556       $tab[25]['field']         = 'postcode';
00557       $tab[25]['name']          = __('Postal code');
00558       $tab[25]['datatype']      = 'string';
00559 
00560       $tab[26]['table']         = $this->getTable();
00561       $tab[26]['field']         = 'cartridges_alert_repeat';
00562       $tab[26]['name']          = __('Alarms on cartridges');
00563       $tab[26]['massiveaction'] = false;
00564       $tab[26]['nosearch']      = true;
00565       $tab[26]['datatype']      = 'specific';
00566 
00567       $tab[27]['table']         = $this->getTable();
00568       $tab[27]['field']         = 'consumables_alert_repeat';
00569       $tab[27]['name']          = __('Alarms on consumables');
00570       $tab[27]['massiveaction'] = false;
00571       $tab[27]['nosearch']      = true;
00572       $tab[27]['datatype']      = 'specific';
00573 
00574       $tab[28]['table']         = $this->getTable();
00575       $tab[28]['field']         = 'notepad';
00576       $tab[28]['name']          = __('Notes');
00577       $tab[28]['datatype']      = 'text';
00578 
00579       $tab[29]['table']         = $this->getTable();
00580       $tab[29]['field']         = 'use_licenses_alert';
00581       $tab[29]['name']          = __('Alarms on expired licenses');
00582       $tab[29]['massiveaction'] = false;
00583       $tab[29]['nosearch']      = true;
00584       $tab[29]['datatype']      = 'specific';
00585 
00586       $tab[53]['table']         = $this->getTable();
00587       $tab[53]['field']         = 'send_licenses_alert_before_delay';
00588       $tab[53]['name']          = __('Send license alarms before');
00589       $tab[53]['massiveaction'] = false;
00590       $tab[53]['nosearch']      = true;
00591       $tab[53]['datatype']      = 'specific';
00592 
00593       $tab[30]['table']         = $this->getTable();
00594       $tab[30]['field']         = 'use_contracts_alert';
00595       $tab[30]['name']          = __('Alarms on contracts');
00596       $tab[30]['massiveaction'] = false;
00597       $tab[30]['nosearch']      = true;
00598       $tab[30]['datatype']      = 'specific';
00599 
00600       $tab[54]['table']         = $this->getTable();
00601       $tab[54]['field']         = 'send_contracts_alert_before_delay';
00602       $tab[54]['name']          = __('Send contract alarms before');
00603       $tab[54]['massiveaction'] = false;
00604       $tab[54]['nosearch']      = true;
00605       $tab[54]['datatype']      = 'specific';
00606 
00607       $tab[31]['table']         = $this->getTable();
00608       $tab[31]['field']         = 'use_infocoms_alert';
00609       $tab[31]['name']          = __('Alarms on financial and administrative information');
00610       $tab[31]['massiveaction'] = false;
00611       $tab[31]['nosearch']      = true;
00612       $tab[31]['datatype']      = 'specific';
00613 
00614       $tab[55]['table']         = $this->getTable();
00615       $tab[55]['field']         = 'send_infocoms_alert_before_delay';
00616       $tab[55]['name']          = __('Send financial and administrative information alarms before');
00617       $tab[55]['massiveaction'] = false;
00618       $tab[55]['nosearch']      = true;
00619       $tab[55]['datatype']      = 'specific';
00620 
00621       $tab[32]['table']         = $this->getTable();
00622       $tab[32]['field']         = 'use_reservations_alert';
00623       $tab[32]['name']          = __('Alerts on reservations');
00624       $tab[32]['massiveaction'] = false;
00625       $tab[32]['nosearch']      = true;
00626       $tab[32]['datatype']      = 'specific';
00627 
00628       $tab[33]['table']         = $this->getTable();
00629       $tab[33]['field']         = 'autoclose_delay';
00630       $tab[33]['name']          = __('Automatic closing of solved tickets after');
00631       $tab[33]['massiveaction'] = false;
00632       $tab[33]['nosearch']      = true;
00633       $tab[33]['datatype']      = 'number';
00634       $tab[33]['min']           = 1;
00635       $tab[33]['max']           = 99;
00636       $tab[33]['step']          = 1;
00637       $tab[33]['unit']          = 'day';
00638       $tab[33]['toadd']         = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'),
00639                                         self::CONFIG_NEVER  => __('Never'),
00640                                         0                   => __('Immediatly'));
00641 
00642       $tab[34]['table']         = $this->getTable();
00643       $tab[34]['field']         = 'notclosed_delay';
00644       $tab[34]['name']          = __('Alerts on tickets which are not solved');
00645       $tab[34]['massiveaction'] = false;
00646       $tab[34]['nosearch']      = true;
00647       $tab[34]['datatype']      = 'specific';
00648 
00649       $tab[35]['table']         = $this->getTable();
00650       $tab[35]['field']         = 'auto_assign_mode';
00651       $tab[35]['name']          = __('Automatic assignment of tickets');
00652       $tab[35]['massiveaction'] = false;
00653       $tab[35]['nosearch']      = true;
00654       $tab[35]['datatype']      = 'specific';
00655 
00656       $tab[36]['table']         = $this->getTable();
00657       $tab[36]['field']         = 'calendars_id'; // not a dropdown because of special value
00658       $tab[36]['name']          = __('Calendar');
00659       $tab[36]['massiveaction'] = false;
00660       $tab[36]['nosearch']      = true;
00661       $tab[36]['datatype']      = 'specific';
00662 
00663       $tab[37]['table']         = $this->getTable();
00664       $tab[37]['field']         = 'tickettype';
00665       $tab[37]['name']          = __('Tickets default type');
00666       $tab[37]['massiveaction'] = false;
00667       $tab[37]['nosearch']      = true;
00668       $tab[37]['datatype']      = 'specific';
00669 
00670       $tab[38]['table']         = $this->getTable();
00671       $tab[38]['field']         = 'autofill_buy_date';
00672       $tab[38]['name']          = __('Date of purchase');
00673       $tab[38]['massiveaction'] = false;
00674       $tab[38]['nosearch']      = true;
00675       $tab[38]['datatype']      = 'specific';
00676 
00677       $tab[39]['table']         = $this->getTable();
00678       $tab[39]['field']         = 'autofill_order_date';
00679       $tab[39]['name']          = __('Order date');
00680       $tab[39]['massiveaction'] = false;
00681       $tab[39]['nosearch']      = true;
00682       $tab[39]['datatype']      = 'specific';
00683 
00684       $tab[40]['table']         = $this->getTable();
00685       $tab[40]['field']         = 'autofill_delivery_date';
00686       $tab[40]['name']          = __('Delivery date');
00687       $tab[40]['massiveaction'] = false;
00688       $tab[40]['nosearch']      = true;
00689       $tab[40]['datatype']      = 'specific';
00690 
00691       $tab[41]['table']         = $this->getTable();
00692       $tab[41]['field']         = 'autofill_use_date';
00693       $tab[41]['name']          = __('Startup date');
00694       $tab[41]['massiveaction'] = false;
00695       $tab[41]['nosearch']      = true;
00696       $tab[41]['datatype']      = 'specific';
00697 
00698       $tab[42]['table']         = $this->getTable();
00699       $tab[42]['field']         = 'autofill_warranty_date';
00700       $tab[42]['name']          = __('Start date of warranty');
00701       $tab[42]['massiveaction'] = false;
00702       $tab[42]['nosearch']      = true;
00703       $tab[42]['datatype']      = 'specific';
00704 
00705       $tab[43]['table']         = $this->getTable();
00706       $tab[43]['field']         = 'inquest_config';
00707       $tab[43]['name']          = __('Satisfaction survey configuration');
00708       $tab[43]['massiveaction'] = false;
00709       $tab[43]['nosearch']      = true;
00710       $tab[43]['datatype']      = 'specific';
00711 
00712       $tab[44]['table']         = $this->getTable();
00713       $tab[44]['field']         = 'inquest_rate';
00714       $tab[44]['name']          = __('Satisfaction survey trigger rate');
00715       $tab[44]['massiveaction'] = false;
00716       $tab[44]['datatype']      = 'number';
00717 
00718       $tab[45]['table']         = $this->getTable();
00719       $tab[45]['field']         = 'inquest_delay';
00720       $tab[45]['name']          = __('Create survey after');
00721       $tab[45]['massiveaction'] = false;
00722       $tab[45]['datatype']      = 'number';
00723 
00724       $tab[46]['table']         = $this->getTable();
00725       $tab[46]['field']         = 'inquest_URL';
00726       $tab[46]['name']          = __('URL');
00727       $tab[46]['massiveaction'] = false;
00728       $tab[46]['datatype']      = 'string';
00729 
00730       $tab[47]['table']         = $this->getTable();
00731       $tab[47]['field']         = 'tickettemplates_id';  // not a dropdown because of special value
00732       $tab[47]['name']          = _n('Ticket template', 'Ticket templates', 1);
00733       $tab[47]['massiveaction'] = false;
00734       $tab[47]['nosearch']      = true;
00735       $tab[47]['datatype']      = 'specific';
00736 
00737       $tab[48]['table']         = $this->getTable();
00738       $tab[48]['field']         = 'default_contract_alert';
00739       $tab[48]['name']          =__('Default value for alarms on contracts');
00740       $tab[48]['massiveaction'] = false;
00741       $tab[48]['nosearch']      = true;
00742       $tab[48]['datatype']      = 'specific';
00743 
00744       $tab[49]['table']         = $this->getTable();
00745       $tab[49]['field']         = 'default_infocom_alert';
00746       $tab[49]['name']          = __('Default value for alarms on financial and administrative information');
00747       $tab[49]['massiveaction'] = false;
00748       $tab[49]['nosearch']      = true;
00749       $tab[49]['datatype']      = 'specific';
00750 
00751       $tab[50]['table']         = $this->getTable();
00752       $tab[50]['field']         = 'default_cartridges_alarm_threshold';
00753       $tab[50]['name']          = __('Default threshold for cartridges count');
00754       $tab[50]['massiveaction'] = false;
00755       $tab[50]['nosearch']      = true;
00756       $tab[50]['datatype']      = 'number';
00757 
00758       $tab[52]['table']         = $this->getTable();
00759       $tab[52]['field']         = 'default_consumables_alarm_threshold';
00760       $tab[52]['name']          = __('Default threshold for consumables count');
00761       $tab[52]['massiveaction'] = false;
00762       $tab[52]['nosearch']      = true;
00763       $tab[52]['datatype']      = 'number';
00764 
00765       $tab[51]['table']         = $this->getTable();
00766       $tab[51]['field']         = 'entities_id_software';   // not a dropdown because of special value
00767                                   //TRANS: software in plural
00768       $tab[51]['name']          = __('Entity for software creation');
00769       $tab[51]['massiveaction'] = false;
00770       $tab[51]['nosearch']      = true;
00771       $tab[51]['datatype']      = 'specific';
00772 
00773       return $tab;
00774    }
00775 
00776 
00777    /**
00778     * Display entities of the loaded profile
00779     *
00780     * @param $target target for entity change action
00781     * @param $myname select name
00782    **/
00783    static function showSelector($target, $myname) {
00784       global $CFG_GLPI;
00785 
00786       $rand = mt_rand();
00787 
00788       echo "<div class='center'>";
00789       echo "<span class='b'>".__('Select the desired entity')."<br>( <img src='".$CFG_GLPI["root_doc"].
00790             "/pics/entity_all.png' alt=''> ".__s('to see the entity and its sub-entities').")</span>".
00791             "<br>";
00792       echo "<a style='font-size:14px;' href='".$target."?active_entity=all' title=\"".
00793              __s('Show all')."\">".str_replace(" ","&nbsp;",__('Show all'))."</a></div>";
00794 
00795       echo "<div class='left' style='width:100%'>";
00796 
00797       echo "<script type='javascript'>";
00798       echo "var Tree_Category_Loader$rand = new Ext.tree.TreeLoader({
00799          dataUrl:'".$CFG_GLPI["root_doc"]."/ajax/entitytreesons.php'
00800       });";
00801 
00802       echo "var Tree_Category$rand = new Ext.tree.TreePanel({
00803          collapsible      : false,
00804          animCollapse     : false,
00805          border           : false,
00806          id               : 'tree_projectcategory$rand',
00807          el               : 'tree_projectcategory$rand',
00808          autoScroll       : true,
00809          animate          : false,
00810          enableDD         : true,
00811          containerScroll  : true,
00812          height           : 320,
00813          width            : 770,
00814          loader           : Tree_Category_Loader$rand,
00815          rootVisible      : false
00816       });";
00817 
00818       // SET the root node.
00819       echo "var Tree_Category_Root$rand = new Ext.tree.AsyncTreeNode({
00820          text     : '',
00821          draggable   : false,
00822          id    : '-1'                  // this IS the id of the startnode
00823       });
00824       Tree_Category$rand.setRootNode(Tree_Category_Root$rand);";
00825 
00826       // Render the tree.
00827       echo "Tree_Category$rand.render();
00828             Tree_Category_Root$rand.expand();";
00829 
00830       echo "</script>";
00831 
00832       echo "<div id='tree_projectcategory$rand' ></div>";
00833       echo "</div>";
00834    }
00835 
00836 
00837    /**
00838     * @since version 0.83 (before addRule)
00839     *
00840     * @param $input array of values
00841    **/
00842    function executeAddRule($input) {
00843 
00844       $this->check($_POST["affectentity"], 'w');
00845 
00846       $collection = RuleCollection::getClassByType($_POST['sub_type']);
00847       $rule       = $collection->getRuleClass($_POST['sub_type']);
00848       $ruleid     = $rule->add($_POST);
00849 
00850       if ($ruleid) {
00851          //Add an action associated to the rule
00852          $ruleAction = new RuleAction();
00853 
00854          //Action is : affect computer to this entity
00855          $ruleAction->addActionByAttributes("assign", $ruleid, "entities_id",
00856                                             $_POST["affectentity"]);
00857 
00858          switch ($_POST['sub_type']) {
00859             case 'RuleRight' :
00860                if ($_POST["profiles_id"]) {
00861                   $ruleAction->addActionByAttributes("assign", $ruleid, "profiles_id",
00862                                                      $_POST["profiles_id"]);
00863                }
00864                $ruleAction->addActionByAttributes("assign", $ruleid, "is_recursive",
00865                                                   $_POST["is_recursive"]);
00866          }
00867       }
00868 
00869       Event::log($ruleid, "rules", 4, "setup",
00870                  //TRANS: %s is the user login
00871                  sprintf(__('%s adds the item'), $_SESSION["glpiname"]));
00872 
00873       Html::back();
00874    }
00875 
00876 
00877    /**
00878     * get all entities with a notification option set
00879     * manage CONFIG_PARENT (or NULL) value
00880     *
00881     * @param $field  String name of the field to search (>0)
00882     *
00883     * @return Array of id => value
00884    **/
00885    static function getEntitiesToNotify($field) {
00886       global $DB, $CFG_GLPI;
00887 
00888       $entities = array();
00889 
00890       // root entity first
00891       $ent = new self();
00892       if ($ent->getFromDB(0)) {  // always exists
00893          $val = $ent->getField($field);
00894          if ($val > 0) {
00895             $entities[0] = $val;
00896          }
00897       }
00898 
00899       // Others entities in level order (parent first)
00900       $query = "SELECT `glpi_entities`.`id` AS `entity`,
00901                        `glpi_entities`.`entities_id` AS `parent`,
00902                        `glpi_entities`.`$field`
00903                 FROM `glpi_entities`
00904                 ORDER BY `glpi_entities`.`level` ASC";
00905 
00906 
00907       foreach ($DB->request($query) as $entitydatas) {
00908          if ((is_null($entitydatas[$field])
00909               || ($entitydatas[$field] == self::CONFIG_PARENT))
00910              && isset($entities[$entitydatas['parent']])) {
00911 
00912             // config inherit from parent
00913             $entities[$entitydatas['entity']] = $entities[$entitydatas['parent']];
00914 
00915          } else if ($entitydatas[$field] > 0) {
00916 
00917             // config found in entity
00918             $entities[$entitydatas['entity']] = $entitydatas[$field];
00919          }
00920       }
00921 
00922       return $entities;
00923    }
00924 
00925 
00926    /**
00927     * @since version 0.84
00928     *
00929     * @param $entity Entity object
00930    **/
00931    static function showStandardOptions(Entity $entity) {
00932 
00933       $con_spotted = false;
00934       $ID          = $entity->getField('id');
00935       if (!$entity->can($ID,'r')) {
00936          return false;
00937       }
00938 
00939       // Entity right applied
00940       $canedit = $entity->can($ID, 'w');
00941 
00942       echo "<div class='spaced'>";
00943       if ($canedit) {
00944          echo "<form method='post' name=form action='".Toolbox::getItemTypeFormURL(__CLASS__)."'>";
00945       }
00946 
00947       echo "<table class='tab_cadre_fixe'>";
00948       echo "<tr><th colspan='4'>".__('Address')."</th></tr>";
00949 
00950       echo "<tr class='tab_bg_1'>";
00951       echo "<td>". __('Phone')."</td>";
00952       echo "<td>";
00953       Html::autocompletionTextField($entity, "phonenumber");
00954       echo "</td>";
00955       echo "<td rowspan='7'>".__('Address')."</td>";
00956       echo "<td rowspan='7'>";
00957       echo "<textarea cols='45' rows='8' name='address'>". $entity->fields["address"]."</textarea>";
00958       echo "</td></tr>";
00959 
00960       echo "<tr class='tab_bg_1'>";
00961       echo "<td>".__('Fax')."</td>";
00962       echo "<td>";
00963       Html::autocompletionTextField($entity, "fax");
00964       echo "</td></tr>";
00965       echo "<tr class='tab_bg_1'>";
00966       echo "<td>".__('Website')."</td>";
00967       echo "<td>";
00968       Html::autocompletionTextField($entity, "website");
00969       echo "</td></tr>";
00970 
00971       echo "<tr class='tab_bg_1'>";
00972       echo "<td>"._n('Email', 'Emails', 1)."</td>";
00973       echo "<td>";
00974       Html::autocompletionTextField($entity, "email");
00975       echo "</td></tr>";
00976 
00977       echo "<tr class='tab_bg_1'>";
00978       echo "<td>".__('Postal code')."</td>";
00979       echo "<td>";
00980       Html::autocompletionTextField($entity,"postcode", array('size' => 7));
00981       echo "&nbsp;&nbsp;". __('City'). "&nbsp;";
00982       Html::autocompletionTextField($entity, "town", array('size' => 27));
00983       echo "</td></tr>";
00984 
00985       echo "<tr class='tab_bg_1'>";
00986       echo "<td>".__('State')."</td>";
00987       echo "<td>";
00988       Html::autocompletionTextField($entity, "state");
00989       echo "</td></tr>";
00990 
00991       echo "<tr class='tab_bg_1'>";
00992       echo "<td>".__('Country')."</td>";
00993       echo "<td>";
00994       Html::autocompletionTextField($entity, "country");
00995       echo "</td></tr>";
00996 
00997       if ($canedit) {
00998          echo "<tr>";
00999          echo "<td class='tab_bg_2 center' colspan='4'>";
01000          echo "<input type='hidden' name='id' value='".$entity->fields["id"]."'>";
01001          echo "<input type='submit' name='update' value=\""._sx('button','Save')."\" class='submit'>";
01002 
01003          echo "</td></tr>";
01004          echo "</table>";
01005          Html::closeForm();
01006 
01007       } else {
01008          echo "</table>";
01009       }
01010 
01011       echo "</div>";
01012    }
01013 
01014 
01015    /**
01016     * @since version 0.84 (before in entitydata.class)
01017     *
01018     * @param $entity Entity object
01019    **/
01020    static function showAdvancedOptions(Entity $entity) {
01021       global $DB;
01022 
01023       $con_spotted = false;
01024       $ID          = $entity->getField('id');
01025       if (!$entity->can($ID,'r')) {
01026          return false;
01027       }
01028 
01029       // Entity right applied (could be user_authtype)
01030       $canedit = $entity->can($ID, 'w');
01031 
01032       if ($canedit) {
01033          echo "<form method='post' name=form action='".Toolbox::getItemTypeFormURL(__CLASS__)."'>";
01034       }
01035       echo "<table class='tab_cadre_fixe'>";
01036 
01037       echo "<tr><th colspan='2'>".__('Values for the generic rules for assignment to entities').
01038            "</th></tr>";
01039 
01040       echo "<tr class='tab_bg_1'><td colspan='2' class='center'>".
01041              __('These parameters are used as actions in generic rules for assignment to entities').
01042            "</td></tr>";
01043 
01044       echo "<tr class='tab_bg_1'>";
01045       echo "<td>".__('Information in inventory tool (TAG) representing the entity')."</td>";
01046       echo "<td>";
01047       Html::autocompletionTextField($entity, "tag", array('size' => 100));
01048       echo "</td></tr>";
01049 
01050       if (Toolbox::canUseLdap()) {
01051          echo "<tr class='tab_bg_1'>";
01052          echo "<td>".__('LDAP directory information attribute representing the entity')."</td>";
01053          echo "<td>";
01054          Html::autocompletionTextField($entity, "ldap_dn", array('size' => 100));
01055          echo "</td></tr>";
01056       }
01057 
01058       echo "<tr class='tab_bg_1'>";
01059       echo "<td>".__('Mail domain surrogates entity')."</td>";
01060       echo "<td>";
01061       Html::autocompletionTextField($entity, "mail_domain", array('size' => 100));
01062       echo "</td></tr>";
01063 
01064       if (Toolbox::canUseLdap()) {
01065          echo "<tr><th colspan='2'>".
01066                 __('Values used in the interface to search users from a LDAP directory').
01067               "</th></tr>";
01068 
01069          echo "<tr class='tab_bg_1'>";
01070          echo "<td>".__('LDAP directory of an entity')."</td>";
01071          echo "<td>";
01072          AuthLDAP::dropdown(array('value'      => $entity->fields['authldaps_id'],
01073                                   'emptylabel' => __('Default server'),
01074                                   'condition'  => "`is_active` = '1'"));
01075          echo "</td></tr>";
01076 
01077          echo "<tr class='tab_bg_1'>";
01078          echo "<td>".__('LDAP filter associated to the entity (if necessary)')."</td>";
01079          echo "<td>";
01080          Html::autocompletionTextField($entity, 'entity_ldapfilter', array('size' => 100));
01081          echo "</td></tr>";
01082       }
01083 
01084      if ($canedit) {
01085          echo "<tr>";
01086          echo "<td class='tab_bg_2 center' colspan='2'>";
01087          echo "<input type='hidden' name='id' value='".$entity->fields["id"]."'>";
01088          echo "<input type='submit' name='update' value=\""._sx('button','Save')."\" class='submit'>";
01089 
01090          echo "</td></tr>";
01091          echo "</table>";
01092          Html::closeForm();
01093 
01094       } else {
01095          echo "</table>";
01096       }
01097    }
01098 
01099 
01100    /**
01101     * @since version 0.84 (before in entitydata.class)
01102     *
01103     * @param $entity Entity object
01104    **/
01105    static function showInventoryOptions(Entity $entity) {
01106 
01107       $ID = $entity->getField('id');
01108       if (!$entity->can($ID,'r')) {
01109          return false;
01110       }
01111 
01112       // Notification right applied
01113       $canedit = Session::haveRight('entity', 'w') && Session::haveAccessToEntity($ID);
01114 
01115       echo "<div class='spaced'>";
01116       if ($canedit) {
01117          echo "<form method='post' name=form action='".Toolbox::getItemTypeFormURL(__CLASS__)."'>";
01118       }
01119 
01120       echo "<table class='tab_cadre_fixe'>";
01121       echo "<tr><th colspan='4'>".__('Autofill dates for financial and administrative information').
01122            "</th></tr>";
01123 
01124 
01125       $options[0] = __('No autofill');
01126       if ($ID > 0) {
01127          $options[self::CONFIG_PARENT] = __('Inheritance of the parent entity');
01128       }
01129 
01130       foreach (getAllDatasFromTable('glpi_states') as $state) {
01131          $options[Infocom::ON_STATUS_CHANGE.'_'.$state['id']]
01132                      //TRANS: %s is the name of the state
01133             = sprintf(__('Fill when shifting to state %s'), $state['name']);
01134       }
01135 
01136       $options[Infocom::COPY_WARRANTY_DATE] = __('Copy the start date of warranty');
01137       //Buy date
01138       echo "<tr class='tab_bg_2'>";
01139       echo "<td> " . __('Date of purchase') . "</td>";
01140       echo "<td>";
01141       Dropdown::showFromArray('autofill_buy_date', $options,
01142                               array('value' => $entity->getField('autofill_buy_date')));
01143       echo "</td>";
01144 
01145       //Order date
01146       echo "<td> " . __('Order date') . "</td>";
01147       echo "<td>";
01148       $options[Infocom::COPY_BUY_DATE] = __('Copy the date of purchase');
01149       Dropdown::showFromArray('autofill_order_date', $options,
01150                               array('value' => $entity->getField('autofill_order_date')));
01151       echo "</td></tr>";
01152 
01153       //Delivery date
01154       echo "<tr class='tab_bg_2'>";
01155       echo "<td> " . __('Delivery date') . "</td>";
01156       echo "<td>";
01157       $options[Infocom::COPY_ORDER_DATE] = __('Copy the order date');
01158       Dropdown::showFromArray('autofill_delivery_date', $options,
01159                               array('value' => $entity->getField('autofill_delivery_date')));
01160       echo "</td>";
01161 
01162       //Use date
01163       echo "<td> " . __('Startup date') . " </td>";
01164       echo "<td>";
01165       $options[Infocom::COPY_DELIVERY_DATE] = __('Copy the delivery date');
01166       Dropdown::showFromArray('autofill_use_date', $options,
01167                               array('value' => $entity->getField('autofill_use_date')));
01168       echo "</td></tr>";
01169 
01170       //Warranty date
01171       echo "<tr class='tab_bg_2'>";
01172       echo "<td> " . __('Start date of warranty') . "</td>";
01173       echo "<td>";
01174       $options = array(0                           => __('No autofill'),
01175                        Infocom::COPY_BUY_DATE      => __('Copy the date of purchase'),
01176                        Infocom::COPY_ORDER_DATE    => __('Copy the order date'),
01177                        Infocom::COPY_DELIVERY_DATE => __('Copy the delivery date'));
01178       if ($ID > 0) {
01179          $options[self::CONFIG_PARENT] = __('Inheritance of the parent entity');
01180       }
01181 
01182       Dropdown::showFromArray('autofill_warranty_date', $options,
01183                               array('value' => $entity->getField('autofill_warranty_date')));
01184       echo "</td><td colspan='2'></td></tr>";
01185 
01186       echo "<tr><th colspan='4'>"._n('Software', 'Software', 2)."</th></tr>";
01187       echo "<tr class='tab_bg_2'>";
01188       echo "<td> " . __('Entity for software creation') . "</td>";
01189       echo "<td>";
01190 
01191       $toadd = array(self::CONFIG_NEVER => __('No change of entity')); // Keep software in PC entity
01192       if ($ID > 0) {
01193          $toadd[self::CONFIG_PARENT] = __('Inheritance of the parent entity');
01194       }
01195       $entities = array($entity->fields['entities_id']);
01196       foreach (getAncestorsOf('glpi_entities',  $entity->fields['entities_id']) as $ent) {
01197          if (Session::haveAccessToEntity($ent)) {
01198             $entities[] = $ent;
01199          }
01200       }
01201 
01202       self::dropdown(array('name'     => 'entities_id_software',
01203                            'value'    => $entity->getField('entities_id_software'),
01204                            'toadd'    => $toadd,
01205                            'entity'   => $entities,
01206                            'comments' => false));
01207 
01208       if ($entity->fields['entities_id_software'] == self::CONFIG_PARENT) {
01209          $tid = self::getUsedConfig('entities_id_software', $entity->getField('entities_id'));
01210          echo "<font class='green'>&nbsp;&nbsp;";
01211          echo self::getSpecificValueToDisplay('entities_id_software', $tid);
01212          echo "</font>";
01213       }
01214       echo "</td><td colspan='2'></td></tr>";
01215 
01216       if ($canedit) {
01217          echo "<tr>";
01218          echo "<td class='tab_bg_2 center' colspan='4'>";
01219          echo "<input type='hidden' name='id' value='".$entity->fields["id"]."'>";
01220          echo "<input type='submit' name='update' value=\""._sx('button','Save')."\" class='submit'>";
01221 
01222          echo "</td></tr>";
01223          echo "</table>";
01224          Html::closeForm();
01225 
01226       } else {
01227          echo "</table>";
01228       }
01229 
01230       echo "</div>";
01231 
01232    }
01233 
01234 
01235    /**
01236     * @since version 0.84 (before in entitydata.class)
01237     *
01238     * @param $entity Entity object
01239    **/
01240    static function showNotificationOptions(Entity $entity) {
01241 
01242       $ID = $entity->getField('id');
01243       if (!$entity->can($ID,'r')
01244           || !Session::haveRight('notification','r')) {
01245          return false;
01246       }
01247 
01248       // Notification right applied
01249       $canedit = Session::haveRight('notification','w') && Session::haveAccessToEntity($ID);
01250 
01251       echo "<div class='spaced'>";
01252       if ($canedit) {
01253          echo "<form method='post' name=form action='".Toolbox::getItemTypeFormURL(__CLASS__)."'>";
01254       }
01255 
01256       echo "<table class='tab_cadre_fixe'>";
01257       echo "<tr><th colspan='4'>".__('Notification options')."</th></tr>";
01258 
01259       echo "<tr class='tab_bg_1'>";
01260       echo "<td>".__('Administrator email')."</td>";
01261       echo "<td>";
01262       Html::autocompletionTextField($entity, "admin_email");
01263       echo "</td>";
01264       echo "<td>" . __('Administrator name') . "</td><td>";
01265       Html::autocompletionTextField($entity, "admin_email_name");
01266       echo "</td></tr>";
01267 
01268       echo "<tr class='tab_bg_1'>";
01269       echo "<td>".__('Administrator reply-to email (if needed)')."</td>";
01270       echo "<td>";
01271       Html::autocompletionTextField($entity, "admin_reply");
01272       echo "</td>";
01273       echo "<td>" . __('Response address (if needed)') . "</td><td>";
01274       Html::autocompletionTextField($entity, "admin_reply_name");
01275       echo "</td></tr>";
01276 
01277       echo "<tr class='tab_bg_1'>";
01278       echo "<td>".__('Prefix for notifications')."</td>";
01279       echo "<td>";
01280       Html::autocompletionTextField($entity, "notification_subject_tag");
01281       echo "</td>";
01282       echo "<td colspan='2'>&nbsp;</td>";
01283       echo "</tr>";
01284 
01285       echo "<tr class='tab_bg_1'>";
01286       echo "<td class='middle right'>" . __('Email signature') . "</td>";
01287       echo "<td colspan='3'>";
01288       echo "<textarea cols='60' rows='5' name='mailing_signature'>".
01289              $entity->fields["mailing_signature"]."</textarea>";
01290       echo "</td></tr>";
01291       echo "</table>";
01292 
01293       echo "<table class='tab_cadre_fixe'>";
01294       echo "<tr><th colspan='4'>".__('Alarms options')."</th></tr>";
01295 
01296       echo "<tr class='tab_bg_1'>";
01297       echo "<th colspan='2' rowspan='2'>";
01298       echo _n('Cartridge', 'Cartridges', 2);
01299       echo "</th>";
01300       echo "<td>" . __('Reminders frequency for alarms on cartridges') . "</td><td>";
01301       $default_value = $entity->fields['cartridges_alert_repeat'];
01302       Alert::dropdown(array('name'           => 'cartridges_alert_repeat',
01303                             'value'          => $default_value,
01304                             'inherit_parent' => (($ID > 0) ? 1 : 0)));
01305 
01306       if ($entity->fields['cartridges_alert_repeat'] == self::CONFIG_PARENT) {
01307          $tid = self::getUsedConfig('cartridges_alert_repeat', $entity->getField('entities_id'));
01308          echo "<font class='green'><br>";
01309          echo self::getSpecificValueToDisplay('cartridges_alert_repeat', $tid);
01310          echo "</font>";
01311       }
01312 
01313       echo "</td></tr>";
01314       echo "<tr class='tab_bg_1'><td>" . __('Default threshold for cartridges count') ."</td><td>";
01315       if ($ID > 0) {
01316          $toadd = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'),
01317                         self::CONFIG_NEVER => __('Never'));
01318       } else {
01319          $toadd = array(self::CONFIG_NEVER => __('Never'));
01320       }
01321       Dropdown::showInteger('default_cartridges_alarm_threshold',
01322                             $entity->fields["default_cartridges_alarm_threshold"], 0, 100, 1,
01323                             $toadd);
01324       if ($entity->fields['default_cartridges_alarm_threshold'] == self::CONFIG_PARENT) {
01325          $tid = self::getUsedConfig('default_cartridges_alarm_threshold',
01326                                     $entity->getField('entities_id'));
01327          echo "<font class='green'><br>";
01328          echo self::getSpecificValueToDisplay('default_cartridges_alarm_threshold', $tid);
01329          echo "</font>";
01330       }
01331       echo "</td></tr>";
01332 
01333       echo "<tr class='tab_bg_1'>";
01334       echo "<th colspan='2' rowspan='2'>";
01335       echo _n('Consumable', 'Consumables', 2);
01336       echo "</th>";
01337 
01338       echo "<td>" . __('Reminders frequency for alarms on consumables') . "</td><td>";
01339       $default_value = $entity->fields['consumables_alert_repeat'];
01340       Alert::dropdown(array('name'           => 'consumables_alert_repeat',
01341                             'value'          => $default_value,
01342                             'inherit_parent' => (($ID > 0) ? 1 : 0)));
01343       if ($entity->fields['consumables_alert_repeat'] == self::CONFIG_PARENT) {
01344          $tid = self::getUsedConfig('consumables_alert_repeat', $entity->getField('entities_id'));
01345          echo "<font class='green'><br>";
01346          echo self::getSpecificValueToDisplay('consumables_alert_repeat', $tid);
01347          echo "</font>";
01348       }
01349       echo "</td></tr>";
01350 
01351       echo "<tr class='tab_bg_1'><td>" . __('Default threshold for consumables count') ."</td><td>";
01352       if ($ID > 0) {
01353          $toadd = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'),
01354                         self::CONFIG_NEVER => __('Never'));
01355       } else {
01356          $toadd = array(self::CONFIG_NEVER => __('Never'));
01357       }
01358       Dropdown::showInteger('default_consumables_alarm_threshold',
01359                             $entity->fields["default_consumables_alarm_threshold"], 0, 100, 1,
01360                             $toadd);
01361          if ($entity->fields['default_consumables_alarm_threshold'] == self::CONFIG_PARENT) {
01362          $tid = self::getUsedConfig('default_consumables_alarm_threshold',
01363                                     $entity->getField('entities_id'));
01364          echo "<font class='green'><br>";
01365          echo self::getSpecificValueToDisplay('default_consumables_alarm_threshold', $tid);
01366          echo "</font>";
01367 
01368       }
01369       echo "</td></tr>";
01370 
01371 
01372       echo "<tr class='tab_bg_1'>";
01373       echo "<th colspan='2' rowspan='3'>";
01374       echo _n('Contract', 'Contracts', 2);
01375       echo "</th>";
01376       echo "<td>" . __('Alarms on contracts') . "</td><td>";
01377       $default_value = $entity->fields['use_contracts_alert'];
01378       Alert::dropdownYesNo(array('name'           => "use_contracts_alert",
01379                                  'value'          => $default_value,
01380                                  'inherit_parent' => (($ID > 0) ? 1 : 0)));
01381       if ($entity->fields['use_contracts_alert'] == self::CONFIG_PARENT) {
01382          $tid = self::getUsedConfig('use_contracts_alert', $entity->getField('entities_id'));
01383          echo "<font class='green'><br>";
01384          echo self::getSpecificValueToDisplay('use_contracts_alert', $tid);
01385          echo "</font>";
01386       }
01387       echo "</td></tr>";
01388 
01389       echo "<tr class='tab_bg_1'><td>".__('Default value') . "</td><td>";
01390       Contract::dropdownAlert(array('name'           => "default_contract_alert",
01391                                     'value'          => $entity->fields["default_contract_alert"],
01392                                     'inherit_parent' => (($ID > 0) ? 1 : 0)));
01393       if ($entity->fields['default_contract_alert'] == self::CONFIG_PARENT) {
01394          $tid = self::getUsedConfig('default_contract_alert', $entity->getField('entities_id'));
01395          echo "<font class='green'><br>";
01396          echo self::getSpecificValueToDisplay('default_contract_alert', $tid);
01397          echo "</font>";
01398       }
01399 
01400       echo "</td></tr>";
01401       echo "<tr class='tab_bg_1'><td>" . __('Send contract alarms before')."</td><td>";
01402       Alert::dropdownIntegerNever('send_contracts_alert_before_delay',
01403                                   $entity->fields['send_contracts_alert_before_delay'],
01404                                   array('max'            => 99,
01405                                         'inherit_parent' => (($ID > 0) ? 1 : 0),
01406                                         'unit'           => 'day',
01407                                         'never_string'   => __('No')));
01408       if ($entity->fields['send_contracts_alert_before_delay'] == self::CONFIG_PARENT) {
01409          $tid = self::getUsedConfig('send_contracts_alert_before_delay',
01410                                     $entity->getField('entities_id'));
01411          echo "<font class='green'><br>";
01412          echo self::getSpecificValueToDisplay('send_contracts_alert_before_delay', $tid);
01413          echo "</font>";
01414       }
01415       echo "</td></tr>";
01416 
01417       echo "<tr class='tab_bg_1'>";
01418       echo "<th colspan='2' rowspan='3'>";
01419       _e('Financial and administrative information');
01420       echo "</th>";
01421       echo "<td>" . __('Alarms on financial and administrative information') . "</td><td>";
01422       $default_value = $entity->fields['use_infocoms_alert'];
01423       Alert::dropdownYesNo(array('name'           => "use_infocoms_alert",
01424                                  'value'          => $default_value,
01425                                  'inherit_parent' => (($ID > 0) ? 1 : 0)));
01426       if ($entity->fields['use_infocoms_alert'] == self::CONFIG_PARENT) {
01427          $tid = self::getUsedConfig('use_infocoms_alert', $entity->getField('entities_id'));
01428          echo "<font class='green'><br>";
01429          echo self::getSpecificValueToDisplay('use_infocoms_alert', $tid);
01430          echo "</font>";
01431       }
01432 
01433       echo "</td></tr>";
01434       echo "<tr class='tab_bg_1'><td>" . __('Default value')."</td><td>";
01435       Infocom::dropdownAlert(array('name'           => 'default_infocom_alert',
01436                                    'value'          => $entity->fields["default_infocom_alert"],
01437                                    'inherit_parent' => (($ID > 0) ? 1 : 0)));
01438       if ($entity->fields['default_infocom_alert'] == self::CONFIG_PARENT) {
01439          $tid = self::getUsedConfig('default_infocom_alert', $entity->getField('entities_id'));
01440          echo "<font class='green'><br>";
01441          echo self::getSpecificValueToDisplay('default_infocom_alert', $tid);
01442          echo "</font>";
01443       }
01444 
01445       echo "</td></tr>";
01446       echo "<tr class='tab_bg_1'>";
01447       echo "<td>" . __('Send financial and administrative information alarms before')."</td><td>";
01448       Alert::dropdownIntegerNever('send_infocoms_alert_before_delay',
01449                                   $entity->fields['send_infocoms_alert_before_delay'],
01450                                   array('max'            => 99,
01451                                         'inherit_parent' => (($ID > 0) ? 1 : 0),
01452                                         'unit'           => 'day',
01453                                         'never_string'   => __('No')));
01454       if ($entity->fields['send_infocoms_alert_before_delay'] == self::CONFIG_PARENT) {
01455          $tid = self::getUsedConfig('send_infocoms_alert_before_delay',
01456                                     $entity->getField('entities_id'));
01457          echo "<font class='green'><br>";
01458          echo self::getSpecificValueToDisplay('send_infocoms_alert_before_delay', $tid);
01459          echo "</font>";
01460       }
01461       echo "</td></tr>";
01462 
01463       echo "<tr class='tab_bg_1'>";
01464       echo "<th colspan='2' rowspan='2'>";
01465       echo _n('License', 'Licenses', 2);
01466       echo "</th>";
01467       echo "<td>" . __('Alarms on expired licenses') . "</td><td>";
01468       $default_value = $entity->fields['use_licenses_alert'];
01469       Alert::dropdownYesNo(array('name'           => "use_licenses_alert",
01470                                  'value'          => $default_value,
01471                                  'inherit_parent' => (($ID > 0) ? 1 : 0)));
01472       if ($entity->fields['use_licenses_alert'] == self::CONFIG_PARENT) {
01473          $tid = self::getUsedConfig('use_licenses_alert', $entity->getField('entities_id'));
01474          echo "<font class='green'><br>";
01475          echo self::getSpecificValueToDisplay('use_licenses_alert', $tid);
01476          echo "</font>";
01477       }
01478       echo "</td>";
01479       echo "</td></tr>";
01480       echo "<tr class='tab_bg_1'><td>" . __('Send license alarms before')."</td><td>";
01481       Alert::dropdownIntegerNever('send_licenses_alert_before_delay',
01482                                   $entity->fields['send_licenses_alert_before_delay'],
01483                                   array('max'            => 99,
01484                                         'inherit_parent' => (($ID > 0) ? 1 : 0),
01485                                         'unit'           => 'day',
01486                                         'never_string'   => __('No')));
01487       if ($entity->fields['send_licenses_alert_before_delay'] == self::CONFIG_PARENT) {
01488          $tid = self::getUsedConfig('send_licenses_alert_before_delay',
01489                                     $entity->getField('entities_id'));
01490          echo "<font class='green'><br>";
01491          echo self::getSpecificValueToDisplay('send_licenses_alert_before_delay', $tid);
01492          echo "</font>";
01493       }
01494 
01495       echo "</td></tr>";
01496 
01497       echo "<tr class='tab_bg_1'>";
01498       echo "<th colspan='2' rowspan='1'>";
01499       echo _n('Reservation', 'Reservations', 2);
01500       echo "</th>";
01501       echo "<td>" . __('Alerts on reservations') . "</td><td>";
01502       Alert::dropdownIntegerNever('use_reservations_alert',
01503                                   $entity->fields['use_reservations_alert'],
01504                                   array('max'            => 99,
01505                                         'inherit_parent' => (($ID > 0) ? 1 : 0),
01506                                         'unit'           => 'hour'));
01507       if ($entity->fields['use_reservations_alert'] == self::CONFIG_PARENT) {
01508          $tid = self::getUsedConfig('use_reservations_alert', $entity->getField('entities_id'));
01509          echo "<font class='green'><br>";
01510          echo self::getSpecificValueToDisplay('use_reservations_alert', $tid);
01511          echo "</font>";
01512       }
01513       echo "</td></tr>";
01514 
01515       echo "<tr class='tab_bg_1'>";
01516       echo "<th colspan='2' rowspan='1'>";
01517       echo _n('Ticket', 'Tickets', 2);
01518       echo "</th>";
01519       echo "<td >". __('Alerts on tickets which are not solved since'). "</td><td>";
01520       Alert::dropdownIntegerNever('notclosed_delay', $entity->fields["notclosed_delay"],
01521                                   array('max'            => 99,
01522                                         'inherit_parent' => (($ID > 0) ? 1 : 0),
01523                                         'unit'           => 'day'));
01524       if ($entity->fields['notclosed_delay'] == self::CONFIG_PARENT) {
01525          $tid = self::getUsedConfig('notclosed_delay', $entity->getField('entities_id'));
01526          echo "<font class='green'><br>";
01527          echo self::getSpecificValueToDisplay('notclosed_delay', $tid);
01528          echo "</font>";
01529       }
01530       echo "</td></tr>";
01531 
01532       if ($canedit) {
01533          echo "<tr>";
01534          echo "<td class='tab_bg_2 center' colspan='4'>";
01535          echo "<input type='hidden' name='id' value='".$entity->fields["id"]."'>";
01536          echo "<input type='submit' name='update' value=\""._sx('button','Save')."\" class='submit'>";
01537          echo "</td></tr>";
01538          echo "</table>";
01539          Html::closeForm();
01540 
01541       } else {
01542          echo "</table>";
01543       }
01544 
01545       echo "</div>";
01546    }
01547 
01548 
01549    /**
01550     * @since version 0.84 (before in entitydata.class)
01551     *
01552     * @param $field
01553     * @param $value
01554    **/
01555    private static function getEntityIDByField($field,$value) {
01556       global $DB;
01557 
01558       $sql = "SELECT `id`
01559               FROM `glpi_entities`
01560               WHERE `".$field."` = '".$value."'";
01561       $result = $DB->query($sql);
01562 
01563       if ($DB->numrows($result) == 1) {
01564          return $DB->result($result, 0, "id");
01565       }
01566       return -1;
01567    }
01568 
01569 
01570    /**
01571     * @since version 0.84 (before in entitydata.class)
01572     *
01573     * @param $value
01574    **/
01575    static function getEntityIDByDN($value) {
01576       return self::getEntityIDByField("ldap_dn", $value);
01577    }
01578 
01579 
01580    /**
01581     * @since version 0.84
01582     *
01583     * @param $value
01584    **/
01585    static function getEntityIDByCompletename($value) {
01586       return self::getEntityIDByField("completename", $value);
01587    }
01588 
01589 
01590    /**
01591     * @since version 0.84 (before in entitydata.class)
01592     *
01593     * @param $value
01594    **/
01595    static function getEntityIDByTag($value) {
01596       return self::getEntityIDByField("tag", $value);
01597    }
01598 
01599 
01600    /**
01601     * @since version 0.84 (before in entitydata.class)
01602     *
01603     * @param $value
01604    **/
01605    static function getEntityIDByDomain($value) {
01606       return self::getEntityIDByField("mail_domain", $value);
01607    }
01608 
01609 
01610    /**
01611     * @since version 0.84 (before in entitydata.class)
01612     *
01613     * @param $entities_id
01614    **/
01615    static function isEntityDirectoryConfigured($entities_id) {
01616 
01617       $entity = new self();
01618 
01619       if ($entity->getFromDB($entities_id)
01620           && ($entity->getField('authldaps_id') != NOT_AVAILABLE)) {
01621          return true;
01622       }
01623 
01624       //If there's a directory marked as default
01625       if (AuthLdap::getDefault()) {
01626          return true;
01627       }
01628       return false;
01629    }
01630 
01631 
01632    /**
01633     * @since version 0.84 (before in entitydata.class)
01634     *
01635     * @param $entity Entity object
01636    **/
01637    static function showHelpdeskOptions(Entity $entity) {
01638       global $CFG_GLPI;
01639 
01640       $ID = $entity->getField('id');
01641       if (!$entity->can($ID,'r')
01642           || !Session::haveRight('entity_helpdesk','r')) {
01643          return false;
01644       }
01645       $canedit = Session::haveRight('entity_helpdesk','w') && Session::haveAccessToEntity($ID);
01646 
01647       echo "<div class='spaced'>";
01648       if ($canedit) {
01649          echo "<form method='post' name=form action='".Toolbox::getItemTypeFormURL(__CLASS__)."'>";
01650       }
01651 
01652       echo "<table class='tab_cadre_fixe'>";
01653       echo "<tr class='tab_bg_1'><td colspan='2'>"._n('Ticket template', 'Ticket templates', 1).
01654            "</td>";
01655       echo "<td colspan='2'>";
01656       $toadd = array();
01657       if ($ID != 0) {
01658          $toadd = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'));
01659       }
01660       $options = array('value'  => $entity->fields["tickettemplates_id"],
01661                        'entity' => $ID,
01662                        'toadd'  => $toadd);
01663 
01664       TicketTemplate::dropdown($options);
01665 
01666       if (($entity->fields["tickettemplates_id"] == self::CONFIG_PARENT)
01667           && ($ID != 0)) {
01668          echo "<font class='green'>&nbsp;&nbsp;";
01669 
01670          $tt  = new TicketTemplate();
01671          $tid = self::getUsedConfig('tickettemplates_id', $ID, '', 0);
01672          if (!$tid) {
01673             echo Dropdown::EMPTY_VALUE;
01674          } else if ($tt->getFromDB($tid)) {
01675             echo $tt->getLink();
01676          }
01677          echo "</font>";
01678       }
01679       echo "</td></tr>";
01680 
01681       echo "<tr class='tab_bg_1'><td colspan='2'>".__('Calendar')."</td>";
01682       echo "<td colspan='2'>";
01683       $options = array('value'      => $entity->fields["calendars_id"],
01684                        'emptylabel' => __('24/7'));
01685 
01686       if ($ID != 0) {
01687          $options['toadd'] = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'));
01688       }
01689       Calendar::dropdown($options);
01690 
01691       if (($entity->fields["calendars_id"] == self::CONFIG_PARENT)
01692           && ($ID != 0)) {
01693          echo "<font class='green'>&nbsp;&nbsp;";
01694          $calendar = new Calendar();
01695          $cid = self::getUsedConfig('calendars_id', $ID, '', 0);
01696          if (!$cid) {
01697             _e('24/7');
01698          } else if ($calendar->getFromDB($cid)) {
01699             echo $calendar->getLink();
01700          }
01701          echo "</font>";
01702       }
01703       echo "</td></tr>";
01704 
01705       echo "<tr class='tab_bg_1'><td colspan='2'>".__('Tickets default type')."</td>";
01706       echo "<td colspan='2'>";
01707       $toadd = array();
01708       if ($ID != 0) {
01709          $toadd = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'));
01710       }
01711       Ticket::dropdownType('tickettype', array('value' => $entity->fields["tickettype"],
01712                                                'toadd' => $toadd));
01713 
01714       if (($entity->fields['tickettype'] == self::CONFIG_PARENT)
01715           && ($ID != 0)) {
01716          echo "<font class='green'>&nbsp;&nbsp;";
01717          echo Ticket::getTicketTypeName(self::getUsedConfig('tickettype', $ID, '',
01718                                                             Ticket::INCIDENT_TYPE));
01719          echo "</font>";
01720       }
01721       echo "</td></tr>";
01722 
01723       echo "<tr class='tab_bg_1'><td  colspan='2'>".__('Automatic assignment of tickets')."</td>";
01724       echo "<td colspan='2'>";
01725       $autoassign = self::getAutoAssignMode();
01726 
01727       if ($ID == 0) {
01728          unset($autoassign[self::CONFIG_PARENT]);
01729       }
01730 
01731       Dropdown::showFromArray('auto_assign_mode', $autoassign,
01732                               array('value' => $entity->fields["auto_assign_mode"]));
01733 
01734       if (($entity->fields['auto_assign_mode'] == self::CONFIG_PARENT)
01735           && ($ID != 0)) {
01736          $auto_assign_mode = self::getUsedConfig('auto_assign_mode', $entity->fields['entities_id']);
01737          echo "<font class='green'>&nbsp;&nbsp;";
01738          echo $autoassign[$auto_assign_mode];
01739          echo "</font>";
01740       }
01741       echo "</td></tr>";
01742 
01743       echo "<tr><th colspan='4'>".__('Automatic closing configuration')."</th></tr>";
01744 
01745       echo "<tr class='tab_bg_1'>".
01746            "<td colspan='2'>".__('Automatic closing of solved tickets after')."</td>";
01747       echo "<td colspan='2'>";
01748       $autoclose = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'),
01749                          self::CONFIG_NEVER  => __('Never'),
01750                          0                   => __('Immediatly'));
01751       if ($ID == 0) {
01752          unset($autoclose[self::CONFIG_PARENT]);
01753       }
01754 
01755       Dropdown::showInteger('autoclose_delay', $entity->fields['autoclose_delay'], 1, 99, 1,
01756                             $autoclose, array('unit' => 'day'));
01757 
01758       if (($entity->fields['autoclose_delay'] == self::CONFIG_PARENT)
01759           && ($ID != 0)) {
01760          $autoclose_mode = self::getUsedConfig('autoclose_delay', $entity->fields['entities_id'],
01761                                                '', self::CONFIG_NEVER);
01762 
01763          echo "<br><font class='green'>&nbsp;&nbsp;";
01764          if ($autoclose_mode >= 0) {
01765             printf(_n('%d day','%d days',$autoclose_mode), $autoclose_mode);
01766          } else {
01767             echo $autoclose[$autoclose_mode];
01768          }
01769          echo "</font>";
01770       }
01771       echo "</td></tr>";
01772 
01773       echo "<tr><th colspan='4'>".__('Configuring the satisfaction survey')."</th></tr>";
01774 
01775       echo "<tr class='tab_bg_1'>".
01776            "<td colspan='2'>".__('Configuring the satisfaction survey')."</td>";
01777       echo "<td colspan='2'>";
01778 
01779       /// no inquest case = rate 0
01780       $typeinquest = array(self::CONFIG_PARENT  => __('Inheritance of the parent entity'),
01781                            1                    => __('Internal survey'),
01782                            2                    => __('External survey'));
01783 
01784       // No inherit from parent for root entity
01785       if ($ID == 0) {
01786          unset($typeinquest[self::CONFIG_PARENT]);
01787          if ($entity->fields['inquest_config'] == self::CONFIG_PARENT) {
01788             $entity->fields['inquest_config'] = 1;
01789          }
01790       }
01791       $rand = Dropdown::showFromArray('inquest_config', $typeinquest,
01792                                       $options = array('value' => $entity->fields['inquest_config']));
01793       echo "</td></tr>\n";
01794 
01795       // Do not display for root entity in inherit case
01796       if (($entity->fields['inquest_config'] == self::CONFIG_PARENT)
01797           && ($ID !=0)) {
01798          $inquestconfig = self::getUsedConfig('inquest_config', $entity->fields['entities_id']);
01799          $inquestrate   = self::getUsedConfig('inquest_config', $entity->fields['entities_id'],
01800                                               'inquest_rate');
01801          echo "<tr class='tab_bg_1'><td colspan='4' class='green center'>";
01802 
01803          if ($inquestrate == 0) {
01804             _e('Disabled');
01805          } else {
01806             echo $typeinquest[$inquestconfig].'<br>';
01807             $inqconf = self::getUsedConfig('inquest_config', $entity->fields['entities_id'],
01808                                            'inquest_delay');
01809 
01810             printf(_n('%d day','%d days',$inqconf), $inqconf);
01811             echo "<br>";
01812             //TRANS: %d is the percentage. %% to display %
01813             printf(__('%d%%'), $inquestrate);
01814 
01815             if ($inquestconfig == 2) {
01816                echo "<br>";
01817                echo self::getUsedConfig('inquest_config', $entity->fields['entities_id'],
01818                                         'inquest_URL');
01819             }
01820          }
01821          echo "</td></tr>\n";
01822       }
01823 
01824       echo "<tr class='tab_bg_1'><td colspan='4'>";
01825 
01826       $_POST  = array('inquest_config' => $entity->fields['inquest_config'],
01827                       'entities_id'    => $ID);
01828       $params = array('inquest_config' => '__VALUE__',
01829                       'entities_id'    => $ID);
01830       echo "<div id='inquestconfig'>";
01831       include GLPI_ROOT.'/ajax/ticketsatisfaction.php';
01832       echo "</div>\n";
01833 
01834       echo "</td></tr>";
01835 
01836       if ($canedit) {
01837          echo "<tr class='tab_bg_2'>";
01838          echo "<td class='center' colspan='4'>";
01839          echo "<input type='hidden' name='id' value='".$entity->fields["id"]."'>";
01840          echo "<input type='submit' name='update' value=\""._sx('button','Save')."\"
01841                   class='submit'>";
01842 
01843          echo "</td></tr>";
01844          echo "</table>";
01845          Html::closeForm();
01846 
01847       } else {
01848          echo "</table>";
01849       }
01850 
01851       echo "</div>";
01852 
01853       Ajax::updateItemOnSelectEvent("dropdown_inquest_config$rand", "inquestconfig",
01854                                     $CFG_GLPI["root_doc"]."/ajax/ticketsatisfaction.php", $params);
01855    }
01856 
01857 
01858    /**
01859     * Retrieve data of current entity or parent entity
01860     *
01861     * @since version 0.84 (before in entitydata.class)
01862     *
01863     * @param $fieldref        string   name of the referent field to know if we look at parent entity
01864     * @param $entities_id
01865     * @param $fieldval        string   name of the field that we want value (default '')
01866     * @param $default_value            value to return (default -2)
01867    **/
01868    static function getUsedConfig($fieldref, $entities_id, $fieldval='', $default_value=-2) {
01869 
01870       // for calendar
01871       if (empty($fieldval)) {
01872          $fieldval = $fieldref;
01873       }
01874 
01875       $entity = new self();
01876       // Search in entity data of the current entity
01877       if ($entity->getFromDB($entities_id)) {
01878          // Value is defined : use it
01879          if (isset($entity->fields[$fieldref])) {
01880             // Numerical value
01881             if (is_numeric($default_value)
01882                 && ($entity->fields[$fieldref] != self::CONFIG_PARENT)) {
01883                return $entity->fields[$fieldval];
01884             }
01885             // String value
01886             if (!is_numeric($default_value)
01887                 && $entity->fields[$fieldref]) {
01888                return $entity->fields[$fieldval];
01889             }
01890          }
01891       }
01892 
01893       // Entity data not found or not defined : search in parent one
01894       if ($entities_id > 0) {
01895 
01896          if ($entity->getFromDB($entities_id)) {
01897             $ret = self::getUsedConfig($fieldref, $entity->fields['entities_id'], $fieldval,
01898                                        $default_value);
01899             return $ret;
01900 
01901          }
01902       }
01903 /*
01904       switch ($fieldval) {
01905          case "tickettype" :
01906             // Default is Incident if not set
01907             return Ticket::INCIDENT_TYPE;
01908       }
01909       */
01910       return $default_value;
01911    }
01912 
01913 
01914    /**
01915     * Generate link for ticket satisfaction
01916     *
01917     * @since version 0.84 (before in entitydata.class)
01918     *
01919     * @param $ticket ticket object
01920     *
01921     * @return url contents
01922    **/
01923    static function generateLinkSatisfaction($ticket) {
01924       global $DB;
01925 
01926       $url = self::getUsedConfig('inquest_config', $ticket->fields['entities_id'], 'inquest_URL');
01927 
01928       if (strstr($url,"[TICKET_ID]")) {
01929          $url = str_replace("[TICKET_ID]", $ticket->fields['id'], $url);
01930       }
01931 
01932       if (strstr($url,"[TICKET_NAME]")) {
01933          $url = str_replace("[TICKET_NAME]", urlencode($ticket->fields['name']), $url);
01934       }
01935 
01936       if (strstr($url,"[TICKET_CREATEDATE]")) {
01937          $url = str_replace("[TICKET_CREATEDATE]", $ticket->fields['date'], $url);
01938       }
01939 
01940       if (strstr($url,"[TICKET_SOLVEDATE]")) {
01941          $url = str_replace("[TICKET_SOLVEDATE]", $ticket->fields['solvedate'], $url);
01942       }
01943 
01944       if (strstr($url,"[REQUESTTYPE_ID]")) {
01945          $url = str_replace("[REQUESTTYPE_ID]", $ticket->fields['requesttypes_id'], $url);
01946       }
01947 
01948       if (strstr($url,"[REQUESTTYPE_NAME]")) {
01949          $url = str_replace("[REQUESTTYPE_NAME]",
01950                             urlencode(Dropdown::getDropdownName('glpi_requesttypes',
01951                                                                 $ticket->fields['requesttypes_id'])),
01952                             $url);
01953       }
01954 
01955       if (strstr($url,"[ITEMTYPE]")
01956           && $ticket->fields['itemtype']
01957           && ($objet = getItemForItemtype($ticket->fields['itemtype']))) {
01958          $url = str_replace("[ITEMTYPE]", urlencode($objet->getTypeName(1)), $url);
01959       }
01960 
01961       if (strstr($url,"[ITEM_ID]")) {
01962          $url = str_replace("[ITEM_ID]", $ticket->fields['items_id'], $url);
01963       }
01964 
01965       if (strstr($url,"[ITEM_NAME]")
01966           && $ticket->fields['itemtype']
01967           && ($objet = getItemForItemtype($ticket->fields['itemtype']))) {
01968          if ($objet->getFromDB($ticket->fields['items_id'])) {
01969             $url = str_replace("[ITEM_NAME]", urlencode($objet->getName()), $url);
01970          }
01971       }
01972 
01973       if (strstr($url,"[TICKET_PRIORITY]")) {
01974          $url = str_replace("[TICKET_PRIORITY]", $ticket->fields['priority'], $url);
01975       }
01976 
01977       if (strstr($url,"[TICKETCATEGORY_ID]")) {
01978          $url = str_replace("[TICKETCATEGORY_ID]", $ticket->fields['itilcategories_id'], $url);
01979       }
01980 
01981       if (strstr($url,"[TICKETCATEGORY_NAME]")) {
01982          $url = str_replace("[TICKETCATEGORY_NAME]",
01983                             urlencode(Dropdown::getDropdownName('glpi_itilcategories',
01984                                                                 $ticket->fields['itilcategories_id'])),
01985                             $url);
01986       }
01987 
01988       if (strstr($url,"[TICKETTYPE_ID]")) {
01989          $url = str_replace("[TICKETTYPE_ID]", $ticket->fields['type'], $url);
01990       }
01991 
01992       if (strstr($url,"[TICKET_TYPENAME]")) {
01993          $url = str_replace("[TICKET_TYPENAME]",
01994                             Ticket::getTicketTypeName($ticket->fields['type']), $url);
01995       }
01996 
01997       if (strstr($url,"[SOLUTIONTYPE_ID]")) {
01998          $url = str_replace("[SOLUTIONTYPE_ID]", $ticket->fields['solutiontypes_id'], $url);
01999       }
02000 
02001       if (strstr($url,"[SOLUTIONTYPE_NAME]")) {
02002          $url = str_replace("[SOLUTIONTYPE_NAME]",
02003                             urlencode(Dropdown::getDropdownName('glpi_solutiontypes',
02004                                                                 $ticket->fields['solutiontypes_id'])),
02005                             $url);
02006       }
02007 
02008       if (strstr($url,"[SLA_ID]")) {
02009          $url = str_replace("[SLA_ID]", $ticket->fields['slas_id'], $url);
02010       }
02011 
02012       if (strstr($url,"[SLA_NAME]")) {
02013          $url = str_replace("[SLA_NAME]",
02014                             urlencode(Dropdown::getDropdownName('glpi_slas',
02015                                                                 $ticket->fields['slas_id'])),
02016                             $url);
02017       }
02018 
02019       if (strstr($url,"[SLALEVEL_ID]")) {
02020          $url = str_replace("[SLALEVEL_ID]", $ticket->fields['slalevels_id'], $url);
02021       }
02022 
02023       if (strstr($url,"[SLALEVEL_NAME]")) {
02024          $url = str_replace("[SLALEVEL_NAME]",
02025                             urlencode(Dropdown::getDropdownName('glpi_slalevels',
02026                                                                 $ticket->fields['slalevels_id'])),
02027                             $url);
02028       }
02029 
02030       return $url;
02031    }
02032 
02033    /**
02034     * get value for auto_assign_mode
02035     *
02036     * @since version 0.84 (created in version 0.83 in entitydata.class)
02037     *
02038     * @param $val if not set, ask for all values, else for 1 value (default NULL)
02039     *
02040     * @return array or string
02041    **/
02042    static function getAutoAssignMode($val=NULL) {
02043 
02044       $tab = array(self::CONFIG_PARENT                  => __('Inheritance of the parent entity'),
02045                    self::CONFIG_NEVER                   => __('No'),
02046                    self::AUTO_ASSIGN_HARDWARE_CATEGORY  => __('Based on the item then the category'),
02047                    self::AUTO_ASSIGN_CATEGORY_HARDWARE  => __('Based on the category then the item'));
02048 
02049       if (is_null($val)) {
02050          return $tab;
02051       }
02052       if (isset($tab[$val])) {
02053          return $tab[$val];
02054       }
02055       return NOT_AVAILABLE;
02056    }
02057 
02058    /**
02059     * @since version 0.84
02060     *
02061     * @param $options array
02062    **/
02063    static function dropdownAutoAssignMode(array $options) {
02064 
02065       $p['name']    = 'auto_assign_mode';
02066       $p['value']   = 0;
02067       $p['display'] = true;
02068 
02069       if (count($options)) {
02070          foreach ($options as $key => $val) {
02071             $p[$key] = $val;
02072          }
02073       }
02074 
02075       $tab = self::getAutoAssignMode();
02076       return Dropdown::showFromArray($p['name'], $tab, $p);
02077    }
02078 
02079 
02080    /**
02081     * @since version 0.84 (before in entitydata.class)
02082     *
02083     * @param $field
02084     * @param $values
02085     * @param $options   array
02086    **/
02087    static function getSpecificValueToDisplay($field, $values, array $options=array()) {
02088 
02089       if (!is_array($values)) {
02090          $values = array($field => $values);
02091       }
02092       switch ($field) {
02093          case 'use_licenses_alert' :
02094          case 'use_contracts_alert' :
02095          case 'use_infocoms_alert' :
02096             if ($values[$field] == self::CONFIG_PARENT) {
02097                return __('Inheritance of the parent entity');
02098             }
02099             return Dropdown::getYesNo($values[$field]);
02100 
02101          case 'use_reservations_alert' :
02102             switch ($values[$field]) {
02103                case self::CONFIG_PARENT :
02104                   return __('Inheritance of the parent entity');
02105 
02106                case 0 :
02107                   return __('Never');
02108             }
02109             return sprintf(_n('%d hour', '%d hours', $values[$field]), $values[$field]);
02110 
02111          case 'default_cartridges_alarm_threshold' :
02112          case 'default_consumables_alarm_threshold' :
02113             switch ($values[$field]) {
02114                case self::CONFIG_PARENT :
02115                   return __('Inheritance of the parent entity');
02116 
02117                case 0 :
02118                   return __('Never');
02119             }
02120             return $values[$field];
02121 
02122          case 'send_contracts_alert_before_delay' :
02123          case 'send_infocoms_alert_before_delay' :
02124          case 'send_licenses_alert_before_delay' :
02125             switch ($values[$field]) {
02126                case self::CONFIG_PARENT :
02127                   return __('Inheritance of the parent entity');
02128 
02129                case 0 :
02130                   return __('No');
02131             }
02132             return sprintf(_n('%d day', '%d days', $values[$field]), $values[$field]);
02133 
02134          case 'cartridges_alert_repeat' :
02135          case 'consumables_alert_repeat' :
02136             switch ($values[$field]) {
02137                case self::CONFIG_PARENT :
02138                   return __('Inheritance of the parent entity');
02139 
02140                case self::CONFIG_NEVER :
02141                case 0 : // For compatibility issue
02142                   return __('Never');
02143 
02144                case DAY_TIMESTAMP :
02145                   return __('Each day');
02146 
02147                case WEEK_TIMESTAMP :
02148                   return __('Each week');
02149 
02150                case MONTH_TIMESTAMP :
02151                   return __('Each month');
02152 
02153                default :
02154                   // Display value if not defined
02155                   return $values[$field];
02156             }
02157             break;
02158 
02159          case 'notclosed_delay' :   // 0 means never
02160             switch ($values[$field]) {
02161                case self::CONFIG_PARENT :
02162                   return __('Inheritance of the parent entity');
02163 
02164                case 0 :
02165                   return __('Never');
02166              }
02167            return sprintf(_n('%d day', '%d days', $values[$field]), $values[$field]);
02168 
02169          case 'auto_assign_mode' :
02170             return self::getAutoAssignMode($values[$field]);
02171 
02172          case 'tickettype' :
02173             if ($values[$field] == self::CONFIG_PARENT) {
02174                return __('Inheritance of the parent entity');
02175             }
02176             return Ticket::getTicketTypeName($values[$field]);
02177 
02178          case 'autofill_buy_date' :
02179          case 'autofill_order_date' :
02180          case 'autofill_delivery_date' :
02181          case 'autofill_use_date' :
02182          case 'autofill_warranty_date' :
02183             switch ($values[$field]) {
02184                case self::CONFIG_PARENT :
02185                   return __('Inheritance of the parent entity');
02186 
02187                case Infocom::COPY_WARRANTY_DATE :
02188                   return __('Copy the start date of warranty');
02189 
02190                case Infocom::COPY_BUY_DATE :
02191                   return __('Copy the date of purchase');
02192 
02193                case Infocom::COPY_ORDER_DATE :
02194                   return __('Copy the order date');
02195 
02196                case Infocom::COPY_DELIVERY_DATE :
02197                   return __('Copy the delivery date');
02198 
02199                default :
02200                   if (strstr($values[$field], '_')) {
02201                      list($type,$sid) = explode('_', $values[$field], 2);
02202                      if ($type == Infocom::ON_STATUS_CHANGE) {
02203                                        // TRANS %s is the name of the state
02204                         return sprintf(__('Fill when shifting to state %s'),
02205                                        Dropdown::getDropdownName('glpi_states', $sid));
02206                      }
02207                   }
02208             }
02209             return __('No autofill');
02210 
02211          case 'inquest_config' :
02212             if ($values[$field] == self::CONFIG_PARENT) {
02213                return __('Inheritance of the parent entity');
02214             }
02215             return TicketSatisfaction::getTypeInquestName($values[$field]);
02216 
02217          case 'default_contract_alert' :
02218             return Contract::getAlertName($values[$field]);
02219 
02220          case 'default_infocom_alert' :
02221             return Infocom::getAlertName($values[$field]);
02222 
02223          case 'entities_id_software' :
02224             if ($values[$field] == self::CONFIG_NEVER) {
02225                return __('No change of entity');
02226             }
02227             if ($values[$field] == self::CONFIG_PARENT) {
02228                return __('Inheritance of the parent entity');
02229             }
02230             return Dropdown::getDropdownName('glpi_entities', $values[$field]);
02231 
02232          case 'tickettemplates_id' :
02233             if ($values[$field] == self::CONFIG_PARENT) {
02234                return __('Inheritance of the parent entity');
02235             }
02236             return Dropdown::getDropdownName('glpi_tickettemplates', $values[$field]);
02237 
02238          case 'calendars_id' :
02239             switch ($values[$field]) {
02240                case self::CONFIG_PARENT :
02241                   return __('Inheritance of the parent entity');
02242 
02243                case 0 :
02244                   return __('24/7');
02245             }
02246             return Dropdown::getDropdownName('glpi_calendars', $values[$field]);
02247 
02248       }
02249       return parent::getSpecificValueToDisplay($field, $values, $options);
02250    }
02251 
02252 
02253    /**
02254     * @since version 0.84
02255     *
02256     * @param $field
02257     * @param $name               (default '')
02258     * @param $values             (default '')
02259     * @param $options      array
02260    **/
02261    static function getSpecificValueToSelect($field, $name='', $values='', array $options=array()) {
02262       global $DB;
02263 
02264       if (!is_array($values)) {
02265          $values = array($field => $values);
02266       }
02267       $options['display'] = false;
02268       switch ($field) {
02269          case 'use_licenses_alert' :
02270          case 'use_contracts_alert' :
02271          case 'use_infocoms_alert' :
02272             $options['name']  = $name;
02273             $options['value'] = $values[$field];
02274             return Alert::dropdownYesNo($options);
02275 
02276          case 'cartridges_alert_repeat' :
02277          case 'consumables_alert_repeat' :
02278             $options['name']  = $name;
02279             $options['value'] = $values[$field];
02280             return Alert::dropdown($options);
02281 
02282          case 'send_contracts_alert_before_delay' :
02283          case 'send_infocoms_alert_before_delay' :
02284          case 'send_licenses_alert_before_delay' :
02285             $options['unit']         = 'day';
02286             $options['never_string'] = __('No');
02287             return Alert::dropdownIntegerNever($name, $values[$field], $options);
02288 
02289          case 'use_reservations_alert' :
02290             $options['unit']  = 'hour';
02291             return Alert::dropdownIntegerNever($name, $values[$field], $options);
02292 
02293          case 'notclosed_delay' :
02294             $options['unit']  = 'hour';
02295             return Alert::dropdownIntegerNever($name, $values[$field], $options);
02296 
02297          case 'auto_assign_mode' :
02298             $options['name']  = $name;
02299             $options['value'] = $values[$field];
02300 
02301             return self::dropdownAutoAssignMode($options);
02302 
02303          case 'tickettype' :
02304             $options['value'] = $values[$field];
02305             $options['toadd'] = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'));
02306             return Ticket::dropdownType($name, $options);
02307 
02308          case 'autofill_buy_date' :
02309          case 'autofill_order_date' :
02310          case 'autofill_delivery_date' :
02311          case 'autofill_use_date' :
02312             $tab[0]                   = __('No autofill');
02313             $tab[self::CONFIG_PARENT] = __('Inheritance of the parent entity');
02314             foreach (getAllDatasFromTable('glpi_states') as $state) {
02315                $tab[Infocom::ON_STATUS_CHANGE.'_'.$state['id']]
02316                            //TRANS: %s is the name of the state
02317                   = sprintf(__('Fill when shifting to state %s'), $state['name']);
02318             }
02319             $tab[Infocom::COPY_WARRANTY_DATE] = __('Copy the start date of warranty');
02320             if ($field != 'autofill_buy_date') {
02321                $tab[Infocom::COPY_BUY_DATE] = __('Copy the date of purchase');
02322                if ($field != 'autofill_order_date') {
02323                   $tab[Infocom::COPY_ORDER_DATE] = __('Copy the order date');
02324                   if ($field != 'autofill_delivery_date') {
02325                      $options[Infocom::COPY_DELIVERY_DATE] = __('Copy the delivery date');
02326                   }
02327                }
02328             }
02329             $options['value'] = $values[$field];
02330             return Dropdown::showFromArray($name, $tab, $options);
02331 
02332          case 'autofill_warranty_date' :
02333             $tab = array(0                           => __('No autofill'),
02334                          Infocom::COPY_BUY_DATE      => __('Copy the date of purchase'),
02335                          Infocom::COPY_ORDER_DATE    => __('Copy the order date'),
02336                          Infocom::COPY_DELIVERY_DATE => __('Copy the delivery date'),
02337                          self::CONFIG_PARENT         => __('Inheritance of the parent entity'));
02338             $options['value'] = $values[$field];
02339             return Dropdown::showFromArray($name, $tab, $options);
02340 
02341          case 'inquest_config' :
02342             $typeinquest = array(self::CONFIG_PARENT  => __('Inheritance of the parent entity'),
02343                                  1                    => __('Internal survey'),
02344                                  2                    => __('External survey'));
02345             $options['value'] = $values[$field];
02346             return Dropdown::showFromArray($name, $typeinquest, $options);
02347 
02348          case 'default_contract_alert' :
02349             $options['name']  = $name;
02350             $options['value'] = $values[$field];
02351             return Contract::dropdownAlert($options);
02352 
02353          case 'default_infocom_alert' :
02354             $options['name']  = $name;
02355             $options['value'] = $values[$field];
02356             return Infocom::dropdownAlert($options);
02357 
02358          case 'entities_id_software' :
02359             $options['toadd'] = array(self::CONFIG_NEVER => __('No change of entity')); // Keep software in PC entity
02360             $options['toadd'][self::CONFIG_PARENT] = __('Inheritance of the parent entity');
02361 
02362             return self::dropdown($options);
02363 
02364       }
02365       return parent::getSpecificValueToSelect($field, $name, $values, $options);
02366    }
02367 
02368 }
02369 ?>