Esempio n. 1
0
             $where .= " OR `glpi_softwares`.`name` " . $search;
         }
         // Also search by id
         if ($displaywith && in_array('id', $_POST['displaywith'])) {
             $where .= " OR `{$table}`.`id` " . $search;
         }
         $where .= ')';
     }
 }
 $addselect = '';
 $addjoin = '';
 if (Session::haveTranslations($_POST['itemtype'], $field)) {
     $addselect .= ", `namet`.`value` AS transname";
     $addjoin .= " LEFT JOIN `glpi_dropdowntranslations` AS namet\n                        ON (`namet`.`itemtype` = '" . $_POST['itemtype'] . "'\n                            AND `namet`.`items_id` = `{$table}`.`id`\n                            AND `namet`.`language` = '" . $_SESSION['glpilanguage'] . "'\n                            AND `namet`.`field` = '{$field}')";
 }
 if (Session::haveTranslations($_POST['itemtype'], 'comment')) {
     $addselect .= ", `commentt`.`value` AS transcomment";
     $addjoin .= " LEFT JOIN `glpi_dropdowntranslations` AS commentt\n                        ON (`commentt`.`itemtype` = '" . $_POST['itemtype'] . "'\n                            AND `commentt`.`items_id` = `{$table}`.`id`\n                            AND `commentt`.`language` = '" . $_SESSION['glpilanguage'] . "'\n                            AND `commentt`.`field` = 'comment')";
 }
 switch ($_POST['itemtype']) {
     case "Contact":
         $query = "SELECT `{$table}`.`entities_id`,\n                          CONCAT(IFNULL(`name`,''),' ',IFNULL(`firstname`,'')) AS {$field},\n                          `{$table}`.`comment`, `{$table}`.`id`\n                   FROM `{$table}`\n                   {$where}";
         break;
     case "SoftwareLicense":
         $query = "SELECT `{$table}`.*,\n                          CONCAT(`glpi_softwares`.`name`,' - ',`glpi_softwarelicenses`.`name`)\n                              AS {$field}\n                   FROM `{$table}`\n                   LEFT JOIN `glpi_softwares`\n                        ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n                   {$where}";
         break;
     case "Profile":
         $query = "SELECT DISTINCT `{$table}`.*\n                   FROM `{$table}`\n                   LEFT JOIN `glpi_profilerights`\n                        ON (`glpi_profilerights`.`profiles_id` = `{$table}`.`id`)\n                   {$where}";
         break;
     default:
         $query = "SELECT `{$table}`.* {$addselect}\n                   FROM `{$table}`\n                   {$addjoin}\n                   {$where}";
Esempio n. 2
0
 /**
  * Generic Function to add left join to a request
  *
  * @param $itemtype                    item type
  * @param $ref_table                   reference table
  * @param $already_link_tables  array  of tables already joined
  * @param $new_table                   new table to join
  * @param $linkfield                   linkfield for LeftJoin
  * @param $meta                        is it a meta item ? (default 0)
  * @param $meta_type                   meta type table (default 0)
  * @param $joinparams           array  join parameters (condition / joinbefore...)
  * @param $field                string field to display (needed for translation join) (default '')
  *
  * @return Left join string
  **/
 static function addLeftJoin($itemtype, $ref_table, array &$already_link_tables, $new_table, $linkfield, $meta = 0, $meta_type = 0, $joinparams = array(), $field = '')
 {
     global $CFG_GLPI;
     // Rename table for meta left join
     $AS = "";
     $nt = $new_table;
     $cleannt = $nt;
     // Virtual field no link
     if (strpos($linkfield, '_virtual') === 0) {
         return false;
     }
     // Multiple link possibilies case
     //       if ($new_table=="glpi_users"
     //           || $new_table=="glpi_groups"
     //           || $new_table=="glpi_users_validation") {
     if (!empty($linkfield) && $linkfield != getForeignKeyFieldForTable($new_table)) {
         $nt .= "_" . $linkfield;
         $AS = " AS `{$nt}`";
     }
     $complexjoin = self::computeComplexJoinID($joinparams);
     if (!empty($complexjoin)) {
         $nt .= "_" . $complexjoin;
         $AS = " AS `{$nt}`";
     }
     //       }
     $addmetanum = "";
     $rt = $ref_table;
     $cleanrt = $rt;
     if ($meta) {
         $addmetanum = "_" . $meta_type;
         $AS = " AS `{$nt}{$addmetanum}`";
         $nt = $nt . $addmetanum;
     }
     // Auto link
     if ($ref_table == $new_table && empty($complexjoin) && ($field == '' || !Session::haveTranslations(getItemTypeForTable($new_table), $field))) {
         return "";
     }
     // Do not take into account standard linkfield
     $tocheck = $nt . "." . $linkfield;
     if ($linkfield == getForeignKeyFieldForTable($new_table)) {
         $tocheck = $nt;
     }
     if (in_array($tocheck, $already_link_tables)) {
         return "";
     }
     array_push($already_link_tables, $tocheck);
     $specific_leftjoin = '';
     // Plugin can override core definition for its type
     if ($plug = isPluginItemType($itemtype)) {
         $function = 'plugin_' . $plug['plugin'] . '_addLeftJoin';
         if (function_exists($function)) {
             $specific_leftjoin = $function($itemtype, $ref_table, $new_table, $linkfield, $already_link_tables);
         }
     }
     // Link with plugin tables : need to know left join structure
     if (empty($specific_leftjoin) && preg_match("/^glpi_plugin_([a-z0-9]+)/", $new_table, $matches)) {
         if (count($matches) == 2) {
             $function = 'plugin_' . $matches[1] . '_addLeftJoin';
             if (function_exists($function)) {
                 $specific_leftjoin = $function($itemtype, $ref_table, $new_table, $linkfield, $already_link_tables);
             }
         }
     }
     if (!empty($linkfield)) {
         $before = '';
         if (isset($joinparams['beforejoin']) && is_array($joinparams['beforejoin'])) {
             if (isset($joinparams['beforejoin']['table'])) {
                 $joinparams['beforejoin'] = array($joinparams['beforejoin']);
             }
             foreach ($joinparams['beforejoin'] as $tab) {
                 if (isset($tab['table'])) {
                     $intertable = $tab['table'];
                     if (isset($tab['linkfield'])) {
                         $interlinkfield = $tab['linkfield'];
                     } else {
                         $interlinkfield = getForeignKeyFieldForTable($intertable);
                     }
                     $interjoinparams = array();
                     if (isset($tab['joinparams'])) {
                         $interjoinparams = $tab['joinparams'];
                     }
                     $before .= self::addLeftJoin($itemtype, $rt, $already_link_tables, $intertable, $interlinkfield, $meta, $meta_type, $interjoinparams);
                 }
                 // No direct link with the previous joins
                 if (!isset($tab['joinparams']['nolink']) || !$tab['joinparams']['nolink']) {
                     $cleanrt = $intertable;
                     $complexjoin = self::computeComplexJoinID($interjoinparams);
                     if (!empty($complexjoin)) {
                         $intertable .= "_" . $complexjoin;
                     }
                     $rt = $intertable . $addmetanum;
                 }
             }
         }
         $addcondition = '';
         if (isset($joinparams['condition'])) {
             $from = array("`REFTABLE`", "REFTABLE", "`NEWTABLE`", "NEWTABLE");
             $to = array("`{$rt}`", "`{$rt}`", "`{$nt}`", "`{$nt}`");
             $addcondition = str_replace($from, $to, $joinparams['condition']);
             $addcondition = $addcondition . " ";
         }
         if (!isset($joinparams['jointype'])) {
             $joinparams['jointype'] = 'standard';
         }
         if (empty($specific_leftjoin)) {
             switch ($new_table) {
                 // No link
                 case "glpi_auth_tables":
                     $user_searchopt = self::getOptions('User');
                     $specific_leftjoin = self::addLeftJoin($itemtype, $rt, $already_link_tables, "glpi_authldaps", 'auths_id', 0, 0, $user_searchopt[30]['joinparams']);
                     $specific_leftjoin .= self::addLeftJoin($itemtype, $rt, $already_link_tables, "glpi_authmails", 'auths_id', 0, 0, $user_searchopt[31]['joinparams']);
                     break;
             }
         }
         if (empty($specific_leftjoin)) {
             switch ($joinparams['jointype']) {
                 case 'child':
                     $linkfield = getForeignKeyFieldForTable($cleanrt);
                     if (isset($joinparams['linkfield'])) {
                         $linkfield = $joinparams['linkfield'];
                     }
                     // Child join
                     $specific_leftjoin = " LEFT JOIN `{$new_table}` {$AS}\n                                             ON (`{$rt}`.`id` = `{$nt}`.`{$linkfield}`\n                                                 {$addcondition})";
                     break;
                 case 'item_item':
                     // Item_Item join
                     $specific_leftjoin = " LEFT JOIN `{$new_table}` {$AS}\n                                          ON ((`{$rt}`.`id`\n                                                = `{$nt}`.`" . getForeignKeyFieldForTable($cleanrt) . "_1`\n                                               OR `{$rt}`.`id`\n                                                 = `{$nt}`.`" . getForeignKeyFieldForTable($cleanrt) . "_2`)\n                                              {$addcondition})";
                     break;
                 case 'item_item_revert':
                     // Item_Item join reverting previous item_item
                     $specific_leftjoin = " LEFT JOIN `{$new_table}` {$AS}\n                                          ON ((`{$nt}`.`id`\n                                                = `{$rt}`.`" . getForeignKeyFieldForTable($cleannt) . "_1`\n                                               OR `{$nt}`.`id`\n                                                 = `{$rt}`.`" . getForeignKeyFieldForTable($cleannt) . "_2`)\n                                              {$addcondition})";
                     break;
                 case "mainitemtype_mainitem":
                     $addmain = 'main';
                 case "itemtype_item":
                     if (!isset($addmain)) {
                         $addmain = '';
                     }
                     $used_itemtype = $itemtype;
                     if (isset($joinparams['specific_itemtype']) && !empty($joinparams['specific_itemtype'])) {
                         $used_itemtype = $joinparams['specific_itemtype'];
                     }
                     // Itemtype join
                     $specific_leftjoin = " LEFT JOIN `{$new_table}` {$AS}\n                                          ON (`{$rt}`.`id` = `{$nt}`.`" . $addmain . "items_id`\n                                              AND `{$nt}`.`" . $addmain . "itemtype` = '{$used_itemtype}'\n                                              {$addcondition}) ";
                     break;
                 case "itemtypeonly":
                     $used_itemtype = $itemtype;
                     if (isset($joinparams['specific_itemtype']) && !empty($joinparams['specific_itemtype'])) {
                         $used_itemtype = $joinparams['specific_itemtype'];
                     }
                     // Itemtype join
                     $specific_leftjoin = " LEFT JOIN `{$new_table}` {$AS}\n                                          ON (`{$nt}`.`itemtype` = '{$used_itemtype}'\n                                              {$addcondition}) ";
                     break;
                 default:
                     // Standard join
                     $specific_leftjoin = "LEFT JOIN `{$new_table}` {$AS}\n                                          ON (`{$rt}`.`{$linkfield}` = `{$nt}`.`id`\n                                              {$addcondition})";
                     $transitemtype = getItemTypeForTable($new_table);
                     if (Session::haveTranslations($transitemtype, $field)) {
                         if (strstr($nt, $field)) {
                             $transAS = $nt . '_trans';
                         } else {
                             $transAS = $nt . "_{$field}" . '_trans';
                         }
                         $specific_leftjoin .= "LEFT JOIN `glpi_dropdowntranslations` AS `{$transAS}`\n                                             ON (`{$transAS}`.`itemtype` = '{$transitemtype}'\n                                                 AND `{$transAS}`.`items_id` = `{$new_table}`.`id`\n                                                 AND `{$transAS}`.`language` = '" . $_SESSION['glpilanguage'] . "'\n                                                 AND `{$transAS}`.`field` = '{$field}')";
                     }
                     break;
             }
         }
         return $before . $specific_leftjoin;
     }
 }
 /**
  * Get translated value for a field in a particular language
  *
  * @param $ID          dropdown item's id
  * @param $itemtype    dropdown itemtype
  * @param $field       the field to look for (default 'name')
  * @param $language    get translation for this language
  * @param $value       default value for the field (default '')
  *
  * @return the translated value of the value in the default language
  **/
 static function getTranslatedValue($ID, $itemtype, $field = 'name', $language, $value = '')
 {
     global $DB;
     //If dropdown translation is globally off, or if this itemtype cannot be translated,
     //then original value should be returned
     $item = new $itemtype();
     if (!$ID || !Session::haveTranslations($itemtype, $field)) {
         return $value;
     }
     //ID > 0 : dropdown item might be translated !
     if ($ID > 0) {
         //There's at least one translation for this itemtype
         if (self::hasItemtypeATranslation($itemtype)) {
             $query = "SELECT `value`\n                      FROM `" . self::getTable() . "`\n                      WHERE `itemtype` = '" . $itemtype . "'\n                            AND `items_id` = '" . $ID . "'\n                            AND `field` = '{$field}'\n                            AND `language` = '{$language}'";
             $result_translations = $DB->query($query);
             //The field is already translated in this language
             if ($DB->numrows($result_translations)) {
                 return $DB->result($result_translations, 0, 'value');
             }
         }
         //Get the value coming from the dropdown table
         $query = "SELECT `{$field}`\n                     FROM `" . getTableForItemType($itemtype) . "`\n                     WHERE `id` = '{$ID}'";
         $results = $DB->query($query);
         if ($DB->numrows($results)) {
             return $DB->result($results, 0, $field);
         }
     }
     return "";
 }
Esempio n. 4
0
 /**
  * Show tasks of a project
  *
  * @param $item Project or ProjectTask object
  *
  * @return nothing
  **/
 static function showFor($item)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if (!$item->canViewItem()) {
         return false;
     }
     $columns = array('name' => self::getTypeName(Session::getPluralNumber()), 'tname' => __('Type'), 'sname' => __('Status'), 'percent_done' => __('Percent done'), 'plan_start_date' => __('Planned start date'), 'plan_end_date' => __('Planned end date'), 'planned_duration' => __('Planned duration'), '_effect_duration' => __('Effective duration'), 'fname' => __('Father'));
     if (isset($_GET["order"]) && $_GET["order"] == "DESC") {
         $order = "DESC";
     } else {
         $order = "ASC";
     }
     if (!isset($_GET["sort"]) || empty($_GET["sort"])) {
         $_GET["sort"] = "plan_start_date";
     }
     if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) {
         $sort = "`" . $_GET["sort"] . "`";
     } else {
         $sort = "`plan_start_date` {$order}, `name`";
     }
     $canedit = false;
     if ($item->getType() == 'Project') {
         $canedit = $item->canEdit($ID);
     }
     switch ($item->getType()) {
         case 'Project':
             $where = "WHERE `glpi_projecttasks`.`projects_id` = '{$ID}'";
             break;
         case 'ProjectTask':
             $where = "WHERE `glpi_projecttasks`.`projecttasks_id` = '{$ID}'";
             break;
         default:
             // Not available type
             return;
     }
     echo "<div class='spaced'>";
     if ($canedit) {
         echo "<div class='center firstbloc'>";
         echo "<a class='vsubmit' href='projecttask.form.php?projects_id={$ID}'>" . _x('button', 'Add a task') . "</a>";
         echo "</div>";
     }
     if ($item->getType() == 'ProjectTask' && $item->can($ID, UPDATE)) {
         $rand = mt_rand();
         echo "<div class='firstbloc'>";
         echo "<form name='projecttask_form{$rand}' id='projecttask_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL('ProjectTask') . "'>";
         $projet = $item->fields['projects_id'];
         echo "<a href='" . Toolbox::getItemTypeFormURL('ProjectTask') . "?projecttasks_id={$ID}&amp;projects_id={$projet}'>";
         _e('Create a sub task from this task of project');
         echo "</a>";
         Html::closeForm();
         echo "</div>";
     }
     $addselect = '';
     $addjoin = '';
     if (Session::haveTranslations('ProjectTaskType', 'name')) {
         $addselect .= ", `namet2`.`value` AS transname2";
         $addjoin .= " LEFT JOIN `glpi_dropdowntranslations` AS namet2\n                           ON (`namet2`.`itemtype` = 'ProjectTaskType'\n                               AND `namet2`.`items_id` = `glpi_projecttasks`.`projecttasktypes_id`\n                               AND `namet2`.`language` = '" . $_SESSION['glpilanguage'] . "'\n                               AND `namet2`.`field` = 'name')";
     }
     if (Session::haveTranslations('ProjectState', 'name')) {
         $addselect .= ", `namet3`.`value` AS transname3";
         $addjoin .= "LEFT JOIN `glpi_dropdowntranslations` AS namet3\n                           ON (`namet3`.`itemtype` = 'ProjectState'\n                               AND `namet3`.`language` = '" . $_SESSION['glpilanguage'] . "'\n                               AND `namet3`.`field` = 'name')";
         $where .= " AND `namet3`.`items_id` = `glpi_projectstates`.`id` ";
     }
     $query = "SELECT `glpi_projecttasks`.*,\n                       `glpi_projecttasktypes`.`name` AS tname,\n                       `glpi_projectstates`.`name` AS sname,\n                       `glpi_projectstates`.`color`,\n                       `father`.`name` AS fname,\n                       `father`.`id` AS fID\n                       {$addselect}\n                FROM `glpi_projecttasks`\n                {$addjoin}\n                LEFT JOIN `glpi_projecttasktypes`\n                   ON (`glpi_projecttasktypes`.`id` = `glpi_projecttasks`.`projecttasktypes_id`)\n                LEFT JOIN `glpi_projectstates`\n                   ON (`glpi_projectstates`.`id` = `glpi_projecttasks`.`projectstates_id`)\n                LEFT JOIN `glpi_projecttasks` as father\n                   ON (`father`.`id` = `glpi_projecttasks`.`projecttasks_id`)\n                {$where}\n                ORDER BY {$sort} {$order}";
     Session::initNavigateListItems('ProjectTask', sprintf(__('%1$s = %2$s'), $item::getTypeName(1), $item->getName()));
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result)) {
             echo "<table class='tab_cadre_fixehov'>";
             $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
             $header = '<tr>';
             foreach ($columns as $key => $val) {
                 // Non order column
                 if ($key[0] == '_') {
                     $header .= "<th>{$val}</th>";
                 } else {
                     $header .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>{$val}</a></th>";
                 }
             }
             $header .= "</tr>\n";
             echo $header;
             while ($data = $DB->fetch_assoc($result)) {
                 Session::addToNavigateListItems('ProjectTask', $data['id']);
                 $rand = mt_rand();
                 echo "<tr class='tab_bg_2'>";
                 echo "<td>";
                 $link = "<a id='ProjectTask" . $data["id"] . $rand . "' href='projecttask.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a>";
                 echo sprintf(__('%1$s %2$s'), $link, Html::showToolTip($data['content'], array('display' => false, 'applyto' => "ProjectTask" . $data["id"] . $rand)));
                 echo "</td>";
                 $name = !empty($data['transname2']) ? $data['transname2'] : $data['tname'];
                 echo "<td>" . $name . "</td>";
                 echo "<td";
                 $statename = !empty($data['transname3']) ? $data['transname3'] : $data['sname'];
                 echo " style=\"background-color:" . $data['color'] . "\"";
                 echo ">" . $statename . "</td>";
                 echo "<td>";
                 echo Dropdown::getValueWithUnit($data["percent_done"], "%");
                 echo "</td>";
                 echo "<td>" . Html::convDateTime($data['plan_start_date']) . "</td>";
                 echo "<td>" . Html::convDateTime($data['plan_end_date']) . "</td>";
                 echo "<td>" . Html::timestampToString($data['planned_duration'], false) . "</td>";
                 echo "<td>" . Html::timestampToString(self::getTotalEffectiveDuration($data['id']), false) . "</td>";
                 echo "<td>";
                 if ($data['projecttasks_id'] > 0) {
                     $father = Dropdown::getDropdownName('glpi_projecttasks', $data['projecttasks_id']);
                     echo "<a id='ProjectTask" . $data["projecttasks_id"] . $rand . "' href='projecttask.form.php?id=" . $data['projecttasks_id'] . "'>" . $father . (empty($father) ? "(" . $data['projecttasks_id'] . ")" : "") . "</a>";
                 }
                 echo "</td></tr>";
             }
             echo $header;
             echo "</table>\n";
         } else {
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr><th>" . __('No item found') . "</th></tr>";
             echo "</table>\n";
         }
     }
     echo "</div>";
 }
Esempio n. 5
0
 /**
  * Get the value of a dropdown
  *
  * Returns the value of the dropdown from $table with ID $id.
  *
  * @param $table        the dropdown table from witch we want values on the select
  * @param $id           id of the element to get
  * @param $withcomment  give array with name and comment (default 0)
  * @param $translate    (true by default)
  * @param $tooltip      boolean  (true by default) returns a tooltip, else returns only 'comment'
  *
  * @return string the value of the dropdown or &nbsp; if not exists
  **/
 static function getDropdownName($table, $id, $withcomment = 0, $translate = true, $tooltip = true)
 {
     global $DB, $CFG_GLPI;
     $item = getItemForItemtype(getItemTypeForTable($table));
     if ($item instanceof CommonTreeDropdown) {
         return getTreeValueCompleteName($table, $id, $withcomment, $translate, $tooltip);
     }
     $name = "";
     $comment = "";
     if ($id) {
         $SELECTNAME = "'' AS transname";
         $SELECTCOMMENT = "'' AS transcomment";
         $JOIN = '';
         if ($translate) {
             if (Session::haveTranslations(getItemTypeForTable($table), 'name')) {
                 $SELECTNAME = "`namet`.`value` AS transname";
                 $JOIN .= " LEFT JOIN `glpi_dropdowntranslations` AS namet\n                                 ON (`namet`.`itemtype` = '" . getItemTypeForTable($table) . "'\n                                     AND `namet`.`items_id` = `{$table}`.`id`\n                                     AND `namet`.`language` = '" . $_SESSION['glpilanguage'] . "'\n                                     AND `namet`.`field` = 'name')";
             }
             if (Session::haveTranslations(getItemTypeForTable($table), 'comment')) {
                 $SELECTCOMMENT = "`namec`.`value` AS transcomment";
                 $JOIN .= " LEFT JOIN `glpi_dropdowntranslations` AS namec\n                                    ON (`namec`.`itemtype` = '" . getItemTypeForTable($table) . "'\n                                        AND `namec`.`items_id` = `{$table}`.`id`\n                                        AND `namec`.`language` = '" . $_SESSION['glpilanguage'] . "'\n                                              AND `namec`.`field` = 'comment')";
             }
         }
         $query = "SELECT `{$table}`.*, {$SELECTNAME}, {$SELECTCOMMENT}\n                   FROM `{$table}`\n                   {$JOIN}\n                   WHERE `{$table}`.`id` = '{$id}'";
         /// TODO review comment management...
         /// TODO getDropdownName need to return only name
         /// When needed to use comment use class instead : getComments function
         /// GetName of class already give Name !!
         /// TODO CommonDBTM : review getComments to be recursive and add informations from class hierarchy
         /// getUserName have the same system : clean it too
         /// Need to study the problem
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result) != 0) {
                 $data = $DB->fetch_assoc($result);
                 if ($translate && !empty($data['transname'])) {
                     $name = $data['transname'];
                 } else {
                     $name = $data["name"];
                 }
                 if (isset($data["comment"])) {
                     if ($translate && !empty($data['transcomment'])) {
                         $comment = $data['transcomment'];
                     } else {
                         $comment = $data["comment"];
                     }
                 }
                 switch ($table) {
                     case "glpi_computers":
                         if (empty($name)) {
                             $name = "({$id})";
                         }
                         break;
                     case "glpi_contacts":
                         //TRANS: %1$s is the name, %2$s is the firstname
                         $name = sprintf(__('%1$s %2$s'), $name, $data["firstname"]);
                         if ($tooltip) {
                             if (!empty($data["phone"])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Phone'), "</span>" . $data['phone']);
                             }
                             if (!empty($data["phone2"])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Phone 2'), "</span>" . $data['phone2']);
                             }
                             if (!empty($data["mobile"])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Mobile phone'), "</span>" . $data['mobile']);
                             }
                             if (!empty($data["fax"])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Fax'), "</span>" . $data['fax']);
                             }
                             if (!empty($data["email"])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Email'), "</span>" . $data['email']);
                             }
                         }
                         break;
                     case "glpi_suppliers":
                         if ($tooltip) {
                             if (!empty($data["phonenumber"])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Phone'), "</span>" . $data['phonenumber']);
                             }
                             if (!empty($data["fax"])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Fax'), "</span>" . $data['fax']);
                             }
                             if (!empty($data["email"])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Email'), "</span>" . $data['email']);
                             }
                         }
                         break;
                     case "glpi_netpoints":
                         $name = sprintf(__('%1$s (%2$s)'), $name, self::getDropdownName("glpi_locations", $data["locations_id"], false, $translate));
                         break;
                     case "glpi_budgets":
                         if ($tooltip) {
                             if (!empty($data['locations_id'])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Location') . "</span>", self::getDropdownName("glpi_locations", $data["locations_id"], false, $translate));
                             }
                             if (!empty($data['budgettypes_id'])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Type') . "</span>", self::getDropdownName("glpi_budgettypes", $data["budgettypes_id"], false, $translate));
                             }
                             if (!empty($data['begin_date'])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('Start date') . "</span>", Html::convDateTime($data["begin_date"]));
                             }
                             if (!empty($data['end_date'])) {
                                 $comment .= "<br>" . sprintf(__('%1$s: %2$s'), "<span class='b'>" . __('End date') . "</span>", Html::convDateTime($data["end_date"]));
                             }
                         }
                 }
             }
         }
     }
     if (empty($name)) {
         $name = "&nbsp;";
     }
     /*
           if (!$item instanceof CommonTreeDropdown) {
              $search  = array("/\&lt;/","/\&gt;/");
              $replace = array("<",">");
              $name    = preg_replace($search, $replace, $name);
           }*/
     if ($withcomment) {
         return array('name' => $name, 'comment' => $comment);
     }
     return $name;
 }
Esempio n. 6
0
 /**
  * @param $ID
  * @param $updateName
  * @param $changeParent
  **/
 function regenerateTreeUnderID($ID, $updateName, $changeParent)
 {
     global $DB;
     if ($updateName || $changeParent) {
         $currentNode = clone $this;
         if ($currentNode->getFromDB($ID)) {
             $currentNodeCompleteName = $currentNode->getField("completename");
             $nextNodeLevel = $currentNode->getField("level") + 1;
         } else {
             $nextNodeLevel = 1;
         }
         $query = "SELECT `id`, `name`\n                   FROM `" . $this->getTable() . "`\n                   WHERE `" . $this->getForeignKeyField() . "` = '{$ID}'";
         if (Session::haveTranslations($this->getType(), 'completename')) {
             DropdownTranslation::regenerateAllCompletenameTranslationsFor($this->getType(), $ID);
         }
         foreach ($DB->request($query) as $data) {
             $query = "UPDATE `" . $this->getTable() . "`\n                      SET ";
             $fieldsToUpdate = array();
             if ($updateName || $changeParent) {
                 if (isset($currentNodeCompleteName)) {
                     $fieldsToUpdate[] = "`completename`='" . self::getCompleteNameFromParents($currentNodeCompleteName, addslashes($data["name"])) . "'";
                 } else {
                     $fieldsToUpdate[] = "`completename`='" . addslashes($data["name"]) . "'";
                 }
             }
             if ($changeParent) {
                 // We have to reset the ancestors as only these changes (ie : not the children).
                 $fieldsToUpdate[] = "`ancestors_cache` = NULL";
                 // And we must update the level of the current node ...
                 $fieldsToUpdate[] = "`level` = '{$nextNodeLevel}'";
             }
             $query .= implode(', ', $fieldsToUpdate) . " WHERE `id`= '" . $data["id"] . "'";
             $DB->query($query);
             // Translations :
             if (Session::haveTranslations($this->getType(), 'completename')) {
                 DropdownTranslation::regenerateAllCompletenameTranslationsFor($this->getType(), $data['id']);
             }
             $this->regenerateTreeUnderID($data["id"], $updateName, $changeParent);
         }
     }
 }
/**
 * Get completename of a Dropdown Tree table
 *
 * @param $table        string   Dropdown Tree table
 * @param $ID           integer  ID of the element
 * @param $withcomment  boolean  1 if you want to give the array with the comments (false by default)
 * @param $translate    boolean  (true by default)
 *
 * @return string : completename of the element
 *
 * @see getTreeLeafValueName
**/
function getTreeValueCompleteName($table, $ID, $withcomment = false, $translate = true)
{
    global $DB;
    $name = "";
    $comment = "";
    $SELECTNAME = "`{$table}`.`completename`, '' AS transname";
    $SELECTCOMMENT = "`{$table}`.`comment`, '' AS transcomment";
    $JOIN = '';
    if ($translate) {
        if (Session::haveTranslations(getItemTypeForTable($table), 'completename')) {
            $SELECTNAME = "`{$table}`.`completename`, `namet`.`value` AS transname";
            $JOIN .= " LEFT JOIN `glpi_dropdowntranslations` AS namet\n                           ON (`namet`.`itemtype` = '" . getItemTypeForTable($table) . "'\n                               AND `namet`.`items_id` = `{$table}`.`id`\n                               AND `namet`.`language` = '" . $_SESSION['glpilanguage'] . "'\n                               AND `namet`.`field` = 'completename')";
        }
        if (Session::haveTranslations(getItemTypeForTable($table), 'comment')) {
            $SELECTCOMMENT = "`{$table}`.`comment`, `namec`.`value` AS transcomment";
            $JOIN .= " LEFT JOIN `glpi_dropdowntranslations` AS namec\n                              ON (`namec`.`itemtype` = '" . getItemTypeForTable($table) . "'\n                                  AND `namec`.`items_id` = `{$table}`.`id`\n                                  AND `namec`.`language` = '" . $_SESSION['glpilanguage'] . "'\n                                  AND `namec`.`field` = 'comment')";
        }
    }
    $query = "SELECT {$SELECTNAME}, {$SELECTCOMMENT}\n             FROM `{$table}`\n             {$JOIN}\n             WHERE `{$table}`.`id` = '{$ID}'";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) == 1) {
            $transname = $DB->result($result, 0, "transname");
            if ($translate && !empty($transname)) {
                $name = $transname;
            } else {
                $name = $DB->result($result, 0, "completename");
            }
            $comment = sprintf(__('%1$s: %2$s') . "<br>", "<span class='b'>" . __('Complete name') . "</span>", $name);
            $comment .= "<span class='b'>&nbsp;" . __('Comments') . "&nbsp;</span>";
            $transcomment = $DB->result($result, 0, "transcomment");
            if ($translate && !empty($transcomment)) {
                $comment .= nl2br($transcomment);
            } else {
                $comment .= nl2br($DB->result($result, 0, "comment"));
            }
        }
    }
    if (empty($name)) {
        $name = "&nbsp;";
    }
    if ($withcomment) {
        return array("name" => $name, "comment" => $comment);
    }
    return $name;
}