.
 --------------------------------------------------------------------------
 */
// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// ----------------------------------------------------------------------
// Class of the defined type
class PluginExampleExample extends CommonDBTM {
   // Should return the localized name of the type
   static function getTypeName($nb = 0) {
      return 'Example Type';
   }
   static function canCreate() {
      if (isset($_SESSION["glpi_plugin_example_profile"])) {
         return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w');
      }
      return false;
   }
   static function canView() {
      if (isset($_SESSION["glpi_plugin_example_profile"])) {
         return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w'
                 || $_SESSION["glpi_plugin_example_profile"]['example'] == 'r');
      }
      return false;
   }
   /**
    * @see CommonGLPI::getMenuName()
   **/
   static function getMenuName() {
      return __('Example plugin');
   }
   
   /**
    * @see CommonGLPI::getAdditionalMenuLinks()
   **/
   static function getAdditionalMenuLinks() {
      global $CFG_GLPI;
      $links = array();
      $links['config'] = '/plugins/example/index.php';
      $links[" "] = '/plugins/example/index.php';
      $links[__s('Test link', 'example')] = '/plugins/example/index.php';
      return $links;
   }
   
   
   function getSearchOptions() {
      $tab = array();
      $tab['common'] = "Header Needed";
      $tab[1]['table']     = 'glpi_plugin_example_examples';
      $tab[1]['field']     = 'name';
      $tab[1]['name']      = __('Name');
      $tab[2]['table']     = 'glpi_plugin_example_dropdowns';
      $tab[2]['field']     = 'name';
      $tab[2]['name']      = __('Dropdown');
      $tab[3]['table']     = 'glpi_plugin_example_examples';
      $tab[3]['field']     = 'serial';
      $tab[3]['name']      = __('Serial number');
      $tab[3]['usehaving'] = true;
      $tab[3]['searchtype'] = 'equals';
      $tab[30]['table']     = 'glpi_plugin_example_examples';
      $tab[30]['field']     = 'id';
      $tab[30]['name']      = __('ID');
      return $tab;
   }
   /**
    * Give localized information about 1 task
    *
    * @param $name of the task
    *
    * @return array of strings
    */
   static function cronInfo($name) {
      switch ($name) {
         case 'Sample' :
            return array('description' => __('Cron description for example', 'example'),
                         'parameter'   => __('Cron parameter for example', 'example'));
      }
      return array();
   }
   /**
    * Execute 1 task manage by the plugin
    *
    * @param $task Object of CronTask class for log / stat
    *
    * @return interger
    *    >0 : done
    *    <0 : to be run again (not finished)
    *     0 : nothing to do
    */
   static function cronSample($task) {
      $task->log("Example log message from class");
      $r = mt_rand(0,$task->fields['param']);
      usleep(1000000+$r*1000);
      $task->setVolume($r);
      return 1;
   }
   // Hook done on before add item case (data from form, not altered)
   static function pre_item_add_computer(Computer $item) {
      if (isset($item->input['name']) && empty($item->input['name'])) {
         Session::addMessageAfterRedirect("Pre Add Computer Hook KO (name empty)", true);
         return $item->input = false;
      } else {
         Session::addMessageAfterRedirect("Pre Add Computer Hook OK", true);
      }
   }
   // Hook done on before add item case (data altered by object prepareInputForAdd)
   static function post_prepareadd_computer(Computer$item) {
      Session::addMessageAfterRedirect("Post prepareAdd Computer Hook", true);
   }
   // Hook done on add item case
   static function item_add_computer(Computer$item) {
      Session::addMessageAfterRedirect("Add Computer Hook, ID=".$item->getID(), true);
      return true;
   }
   function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
      if (!$withtemplate) {
         switch ($item->getType()) {
            case 'Profile' :
               if ($item->getField('central')) {
                  return __('Example', 'example');
               }
               break;
            case 'Phone' :
               if ($_SESSION['glpishow_count_on_tabs']) {
                  return self::createTabEntry(__('Example', 'example'),
                                              countElementsInTable($this->getTable()));
               }
               return __('Example', 'example');
            case 'ComputerDisk' :
            case 'Supplier' :
               return array(1 => __("Test PLugin", 'example'),
                            2 => __("Test PLugin 2", 'example'));
            case 'Computer' :
            case 'Central' :
            case 'Preference':
            case 'Notification':
               return array(1 => __("Test PLugin", 'example'));
         }
      }
      return '';
   }
   static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
      switch ($item->getType()) {
         case 'Phone' :
            _e("Plugin Example on Phone", 'example');
            break;
         case 'Central' :
            _e("Plugin central action", 'example');
            break;
         case 'Preference' :
            // Complete form display
            $data = plugin_version_example();
            echo "
"] = '/plugins/example/index.php';
      $links[__s('Test link', 'example')] = '/plugins/example/index.php';
      return $links;
   }
   
   
   function getSearchOptions() {
      $tab = array();
      $tab['common'] = "Header Needed";
      $tab[1]['table']     = 'glpi_plugin_example_examples';
      $tab[1]['field']     = 'name';
      $tab[1]['name']      = __('Name');
      $tab[2]['table']     = 'glpi_plugin_example_dropdowns';
      $tab[2]['field']     = 'name';
      $tab[2]['name']      = __('Dropdown');
      $tab[3]['table']     = 'glpi_plugin_example_examples';
      $tab[3]['field']     = 'serial';
      $tab[3]['name']      = __('Serial number');
      $tab[3]['usehaving'] = true;
      $tab[3]['searchtype'] = 'equals';
      $tab[30]['table']     = 'glpi_plugin_example_examples';
      $tab[30]['field']     = 'id';
      $tab[30]['name']      = __('ID');
      return $tab;
   }
   /**
    * Give localized information about 1 task
    *
    * @param $name of the task
    *
    * @return array of strings
    */
   static function cronInfo($name) {
      switch ($name) {
         case 'Sample' :
            return array('description' => __('Cron description for example', 'example'),
                         'parameter'   => __('Cron parameter for example', 'example'));
      }
      return array();
   }
   /**
    * Execute 1 task manage by the plugin
    *
    * @param $task Object of CronTask class for log / stat
    *
    * @return interger
    *    >0 : done
    *    <0 : to be run again (not finished)
    *     0 : nothing to do
    */
   static function cronSample($task) {
      $task->log("Example log message from class");
      $r = mt_rand(0,$task->fields['param']);
      usleep(1000000+$r*1000);
      $task->setVolume($r);
      return 1;
   }
   // Hook done on before add item case (data from form, not altered)
   static function pre_item_add_computer(Computer $item) {
      if (isset($item->input['name']) && empty($item->input['name'])) {
         Session::addMessageAfterRedirect("Pre Add Computer Hook KO (name empty)", true);
         return $item->input = false;
      } else {
         Session::addMessageAfterRedirect("Pre Add Computer Hook OK", true);
      }
   }
   // Hook done on before add item case (data altered by object prepareInputForAdd)
   static function post_prepareadd_computer(Computer$item) {
      Session::addMessageAfterRedirect("Post prepareAdd Computer Hook", true);
   }
   // Hook done on add item case
   static function item_add_computer(Computer$item) {
      Session::addMessageAfterRedirect("Add Computer Hook, ID=".$item->getID(), true);
      return true;
   }
   function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
      if (!$withtemplate) {
         switch ($item->getType()) {
            case 'Profile' :
               if ($item->getField('central')) {
                  return __('Example', 'example');
               }
               break;
            case 'Phone' :
               if ($_SESSION['glpishow_count_on_tabs']) {
                  return self::createTabEntry(__('Example', 'example'),
                                              countElementsInTable($this->getTable()));
               }
               return __('Example', 'example');
            case 'ComputerDisk' :
            case 'Supplier' :
               return array(1 => __("Test PLugin", 'example'),
                            2 => __("Test PLugin 2", 'example'));
            case 'Computer' :
            case 'Central' :
            case 'Preference':
            case 'Notification':
               return array(1 => __("Test PLugin", 'example'));
         }
      }
      return '';
   }
   static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
      switch ($item->getType()) {
         case 'Phone' :
            _e("Plugin Example on Phone", 'example');
            break;
         case 'Central' :
            _e("Plugin central action", 'example');
            break;
         case 'Preference' :
            // Complete form display
            $data = plugin_version_example();
            echo "