static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item) { global $DB; $ID = $item->getField('id'); if (!Session::haveRight('knowbase', 'r') || !Session::haveRight('faq', 'r')) { return false; } $knowbaseitemcategories_id = $item->getField('knowbaseitemcategories_id'); $fullcategoryname = Html::clean(getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id)); $question = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('name'), ENT_QUOTES, "UTF-8"))); $answer = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('answer'), ENT_QUOTES, "UTF-8"))); $pdf->setColumnsSize(100); if (Toolbox::strlen($fullcategoryname) > 0) { $pdf->displayTitle('<b>' . __('Category name') . '</b>'); $pdf->displayLine($fullcategoryname); } if (Toolbox::strlen($question) > 0) { $pdf->displayTitle('<b>' . __('Subject') . '</b>'); $pdf->displayText('', $question, 5); } else { $pdf->displayTitle('<b>' . __('No question found', 'pdf') . '</b>'); } if (Toolbox::strlen($answer) > 0) { $pdf->displayTitle('<b>' . __('Content') . '</b>'); $pdf->displayText('', $answer, 5); } else { $pdf->displayTitle('<b>' . __('No answer found') . '</b>'); } $pdf->setColumnsSize(50, 15, 15, 10, 10); $pdf->displayTitle(__('Writer'), __('Creation date'), __('Last update'), __('FAQ'), _n('View', 'Views', 2)); $pdf->displayLine(getUserName($item->fields["users_id"]), Html::convDateTime($item->fields["date"]), Html::convDateTime($item->fields["date_mod"]), Dropdown::getYesNo($item->fields["is_faq"]), $item->fields["view"]); $pdf->displaySpace(); }
/** * Print out (html) show item : question and answer * * @param $options array of options * * @return nothing (display item : question and answer) **/ function showFull($options = array()) { global $DB, $CFG_GLPI; if (!$this->can($this->fields['id'], READ)) { return false; } $linkusers_id = true; // show item : question and answer if (Session::getLoginUserID() === false && $CFG_GLPI["use_public_faq"] || $_SESSION["glpiactiveprofile"]["interface"] == "helpdesk" || !User::canView()) { $linkusers_id = false; } $this->updateCounter(); $knowbaseitemcategories_id = $this->fields["knowbaseitemcategories_id"]; $fullcategoryname = getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id); $tmp = "<a href='" . $this->getSearchURL() . "?knowbaseitemcategories_id={$knowbaseitemcategories_id}'>" . $fullcategoryname . "</a>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . sprintf(__('%1$s: %2$s'), __('Category'), $tmp); echo "</th></tr>"; echo "<tr><td class='left' colspan='4'><h2>" . __('Subject') . "</h2>"; if (KnowbaseItemTranslation::canBeTranslated($this)) { echo KnowbaseItemTranslation::getTranslatedValue($this, 'name'); } else { echo $this->fields["name"]; } echo "</td></tr>"; echo "<tr><td class='left' colspan='4'><h2>" . __('Content') . "</h2>\n"; echo "<div id='kbanswer'>"; if (KnowbaseItemTranslation::canBeTranslated($this)) { $answer = KnowbaseItemTranslation::getTranslatedValue($this, 'answer'); } else { $answer = $this->fields["answer"]; } echo Toolbox::unclean_html_cross_side_scripting_deep($answer); echo "</div>"; echo "</td></tr>"; echo "<tr><th class='tdkb' colspan='2'>"; if ($this->fields["users_id"]) { // Integer because true may be 2 and getUserName return array if ($linkusers_id) { $linkusers_id = 1; } else { $linkusers_id = 0; } printf(__('%1$s: %2$s'), __('Writer'), getUserName($this->fields["users_id"], $linkusers_id)); echo "<br>"; } if ($this->fields["date"]) { //TRANS: %s is the datetime of update printf(__('Created on %s'), Html::convDateTime($this->fields["date"])); echo "<br>"; } if ($this->fields["date_mod"]) { //TRANS: %s is the datetime of update printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"])); } echo "</th>"; echo "<th class='tdkb' colspan='2'>"; if ($this->countVisibilities() == 0) { echo "<span class='red'>" . __('Unpublished') . "</span><br>"; } printf(_n('%d view', '%d views', $this->fields["view"]), $this->fields["view"]); echo "<br>"; if ($this->fields["is_faq"]) { _e('This item is part of the FAQ'); } else { _e('This item is not part of the FAQ'); } echo "</th></tr>"; echo "</table>"; return true; }
/** * Print out (html) show item : question and answer * * @param $linkusers_id display users_id link (true by default) * @param $options array of options * * @return nothing (display item : question and answer) **/ function showFull($linkusers_id = true, $options = array()) { global $DB, $CFG_GLPI; if (!$this->can($this->fields['id'], 'r')) { return false; } // show item : question and answer if (!Session::haveRight("user", "r")) { $linkusers_id = false; } $inpopup = strpos($_SERVER['PHP_SELF'], "popup.php"); $this->updateCounter(); $knowbaseitemcategories_id = $this->fields["knowbaseitemcategories_id"]; $fullcategoryname = getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id); if (!$inpopup) { $this->showTabs($options); } $options['colspan'] = 2; $options['canedit'] = 0; // Hide the buttons $this->showFormHeader($options); $tmp = "<a href='" . $this->getSearchURL() . "?knowbaseitemcategories_id={$knowbaseitemcategories_id}'>" . $fullcategoryname . "</a>"; echo "<tr class='tab_bg_3'><th colspan='4'>" . sprintf(__('%1$s: %2$s'), __('Category'), $tmp); echo "</th></tr>"; echo "<tr class='tab_bg_3'><td class='left' colspan='4'><h2>" . __('Subject') . "</h2>"; echo $this->fields["name"]; echo "</td></tr>"; echo "<tr class='tab_bg_3'><td class='left' colspan='4'><h2>" . __('Content') . "</h2>\n"; echo "<div id='kbanswer'>"; echo Toolbox::unclean_html_cross_side_scripting_deep($this->fields["answer"]); echo "</div>"; echo "</td></tr>"; echo "<tr><th class='tdkb' colspan='2'>"; if ($this->fields["users_id"]) { // Integer because true may be 2 and getUserName return array if ($linkusers_id) { $linkusers_id = 1; } else { $linkusers_id = 0; } printf(__('%1$s: %2$s'), __('Writer'), getUserName($this->fields["users_id"], $linkusers_id)); echo "<br>"; } if ($this->fields["date"]) { //TRANS: %s is the datetime of update printf(__('Created on %s'), Html::convDateTime($this->fields["date"])); } if ($this->countVisibilities() == 0) { echo "<br><span class='red'>" . __('Unpublished') . "</span>"; } echo "</th>"; echo "<th class='tdkb' colspan='2'>"; if ($this->fields["date_mod"]) { //TRANS: %s is the datetime of update printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"])); echo "<br>"; } echo sprintf(_n('%d view', '%d views', $this->fields["view"]), $this->fields["view"]) . "</th></tr>"; $this->showFormButtons($options); if (!$inpopup) { $this->addDivForTabs(); } return true; }
/** * 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 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 = " "; } /* if (!$item instanceof CommonTreeDropdown) { $search = array("/\</","/\>/"); $replace = array("<",">"); $name = preg_replace($search, $replace, $name); }*/ if ($withcomment) { return array('name' => $name, 'comment' => $comment); } return $name; }
/** * 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) * * @return string the value of the dropdown or if not exists **/ static function getDropdownName($table, $id, $withcomment = 0) { global $DB, $CFG_GLPI; $item = getItemForItemtype(getItemTypeForTable($table)); if ($item instanceof CommonTreeDropdown) { return getTreeValueCompleteName($table, $id, $withcomment); } $name = ""; $comment = ""; if ($id) { $query = "SELECT *\n FROM `" . $table . "`\n WHERE `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); $name = $data["name"]; if (isset($data["comment"])) { $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 (!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 (!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"])); break; } } } } if (empty($name)) { $name = " "; } if ($withcomment) { return array('name' => $name, 'comment' => $comment); } return $name; }
/** * 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 * * @return string the value of the dropdown or if not exists **/ static function getDropdownName($table, $id, $withcomment = 0) { global $DB, $CFG_GLPI, $LANG; $itemtype = getItemTypeForTable($table); $item = new $itemtype(); if ($item instanceof CommonTreeDropdown) { return getTreeValueCompleteName($table, $id, $withcomment); } else { $name = ""; $comment = ""; if ($id) { $query = "SELECT *\n FROM `" . $table . "`\n WHERE `id` = '" . $id . "'"; if ($result = $DB->query($query)) { if ($DB->numrows($result) != 0) { $data = $DB->fetch_assoc($result); $name = $data["name"]; if (isset($data["comment"])) { $comment = $data["comment"]; } switch ($table) { case "glpi_computers": if (empty($name)) { $name = "({$id})"; } break; case "glpi_contacts": $name .= " " . $data["firstname"]; if (!empty($data["phone"])) { $comment .= "<br><strong>" . $LANG['help'][35] . " :</strong> " . $data["phone"]; } if (!empty($data["phone2"])) { $comment .= "<br><strong>" . $LANG['help'][35] . " 2 :</strong> " . $data["phone2"]; } if (!empty($data["mobile"])) { $comment .= "<br><strong>" . $LANG['common'][42] . " :</strong> " . $data["mobile"]; } if (!empty($data["fax"])) { $comment .= "<br><strong>" . $LANG['financial'][30] . " :</strong> " . $data["fax"]; } if (!empty($data["email"])) { $comment .= "<br><strong>" . $LANG['setup'][14] . " :</strong> " . $data["email"]; } break; case "glpi_suppliers": if (!empty($data["phonenumber"])) { $comment .= "<br><strong>" . $LANG['help'][35] . " :</strong> " . $data["phonenumber"]; } if (!empty($data["fax"])) { $comment .= "<br><strong>" . $LANG['financial'][30] . " :</strong> " . $data["fax"]; } if (!empty($data["email"])) { $comment .= "<br><strong>" . $LANG['setup'][14] . " :</strong> " . $data["email"]; } break; case "glpi_netpoints": $name .= " (" . self::getDropdownName("glpi_locations", $data["locations_id"]) . ")"; break; } } } } } if (empty($name)) { $name = " "; } if ($withcomment) { return array('name' => $name, 'comment' => $comment); } return $name; }
/** * Print out (html) show item : question and answer * * @param $linkusers_id display users_id link * @param $options array of options * * @return nothing (display item : question and answer) **/ function showFull($linkusers_id = true, $options = array()) { global $DB, $LANG, $CFG_GLPI; if (!$this->can($this->fields['id'], 'r')) { return false; } // show item : question and answer if (!haveRight("user", "r")) { $linkusers_id = false; } $inpopup = strpos($_SERVER['PHP_SELF'], "popup.php"); //update counter view $query = "UPDATE `glpi_knowbaseitems`\n SET `view`=view+1\n WHERE `id` = '" . $this->fields['id'] . "'"; $DB->query($query); $knowbaseitemcategories_id = $this->fields["knowbaseitemcategories_id"]; $fullcategoryname = getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id); if (!$inpopup) { $this->showTabs($options); } $options['colspan'] = 2; $options['canedit'] = 0; // Hide the buttons $this->showFormHeader($options); echo "<tr class='tab_bg_3'><th colspan='4'>" . $LANG['common'][36] . " : "; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/" . (isset($_SESSION['glpiactiveprofile']) && $_SESSION['glpiactiveprofile']['interface'] == "central" ? "knowbaseitem.php" : "helpdesk.faq.php") . "?knowbaseitemcategories_id={$knowbaseitemcategories_id}'>" . $fullcategoryname . "</a>"; echo "</th></tr>"; echo "<tr class='tab_bg_3'><td class='left' colspan='4'><h2>" . $LANG['knowbase'][14] . "</h2>"; echo $this->fields["question"]; echo "</td></tr>"; echo "<tr class='tab_bg_3'><td class='left' colspan='4'><h2>" . $LANG['knowbase'][15] . "</h2>\n"; $answer = unclean_cross_side_scripting_deep($this->fields["answer"]); echo "<div id='kbanswer'>" . $answer . "</div>"; echo "</td></tr>"; echo "<tr><th class='tdkb' colspan='2'>"; if ($this->fields["users_id"]) { echo $LANG['common'][37] . " : "; // Integer because true may be 2 and getUserName return array if ($linkusers_id) { $linkusers_id = 1; } else { $linkusers_id = 0; } echo getUserName($this->fields["users_id"], $linkusers_id); echo "<br>"; } if ($this->fields["date"]) { echo $LANG['knowbase'][27] . " : " . convDateTime($this->fields["date"]); } echo "</th>"; echo "<th class='tdkb' colspan='2'>"; if ($this->fields["date_mod"]) { echo $LANG['common'][26] . " : " . convDateTime($this->fields["date_mod"]) . "<br>"; } echo $LANG['knowbase'][26] . " : " . $this->fields["view"] . "</th></tr>"; $this->showFormButtons($options); if (!$inpopup) { $this->addDivForTabs(); } return true; }