Skip to content

Commit

Permalink
Merge branch 'feature/1216_remove_commondbchild' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Dec 3, 2018
2 parents 1f7443e + 9649c52 commit b2f825b
Show file tree
Hide file tree
Showing 37 changed files with 2,219 additions and 2,086 deletions.
2 changes: 1 addition & 1 deletion front/form_answer.form.php → front/formanswer.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
Html::displayNotFoundError();
}

$formanswer = new PluginFormcreatorForm_Answer();
$formanswer = new PluginFormcreatorFormAnswer();

// Edit an existing target ticket
if (isset($_POST['update'])) {
Expand Down
4 changes: 2 additions & 2 deletions front/form_answer.php → front/formanswer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Html::displayNotFoundError();
}

if (PluginFormcreatorForm_Answer::canView()) {
if (PluginFormcreatorFormAnswer::canView()) {
if (plugin_formcreator_replaceHelpdesk()) {
PluginFormcreatorWizard::header(__('Service catalog', 'formcreator'));
} else {
Expand All @@ -58,7 +58,7 @@
}
}

Search::show('PluginFormcreatorForm_Answer');
Search::show(PluginFormcreatorFormAnswer::class);

if (plugin_formcreator_replaceHelpdesk()) {
PluginFormcreatorWizard::footer();
Expand Down
26 changes: 14 additions & 12 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function plugin_formcreator_install() {
$migration = new Migration($version['version']);
require_once(__DIR__ . '/install/install.php');
$install = new PluginFormcreatorInstall();
if (!$install->isPluginInstalled()) {
if (!$install->isPluginInstalled()
|| isset($_SESSION['plugin_formcreator']['cli'])
&& $_SESSION['plugin_formcreator']['cli'] == 'force-install') {
return $install->install($migration);
}
return $install->upgrade($migration);
Expand Down Expand Up @@ -99,7 +101,7 @@ function plugin_formcreator_canValidate() {

function plugin_formcreator_getCondition($itemtype) {
$table = getTableForItemType($itemtype);
if ($itemtype == PluginFormcreatorForm_Answer::class
if ($itemtype == PluginFormcreatorFormAnswer::class
&& plugin_formcreator_canValidate()) {
$condition = " 1=1 ";

Expand All @@ -125,10 +127,10 @@ function plugin_formcreator_addDefaultWhere($itemtype) {
$condition = str_replace('`users_id_recipient`', '`requester_id`', $condition);
break;

case PluginFormcreatorForm_Answer::class:
case PluginFormcreatorFormAnswer::class:
if (isset($_SESSION['formcreator']['form_search_answers'])
&& $_SESSION['formcreator']['form_search_answers']) {
$condition = "`$table`.`".PluginFormcreatorForm_Answer::$items_id."` = ".
$condition = "`$table`.`".PluginFormcreatorFormAnswer::$items_id."` = ".
$_SESSION['formcreator']['form_search_answers'];
} else {
$condition = plugin_formcreator_getCondition($itemtype);
Expand Down Expand Up @@ -248,7 +250,7 @@ function plugin_formcreator_addWhere($link, $nott, $itemtype, $ID, $val, $search


function plugin_formcreator_AssignToTicket($types) {
$types['PluginFormcreatorForm_Answer'] = PluginFormcreatorForm_Answer::getTypeName();
$types[PluginFormcreatorFormAnswer::class] = PluginFormcreatorFormAnswer::getTypeName();

return $types;
}
Expand Down Expand Up @@ -335,11 +337,11 @@ function plugin_formcreator_hook_delete_ticket(CommonDBTM $item) {
if ($item instanceof Ticket) {
$id = $item->getID();

// mark form_answers as deleted
// mark formanswers as deleted
$item_ticket = new Item_Ticket();
$rows = $item_ticket->find("`itemtype` = 'PluginFormcreatorForm_Answer' AND `tickets_id` = '$id'");
$rows = $item_ticket->find("`itemtype` = 'PluginFormcreatorFormAnswer' AND `tickets_id` = '$id'");
foreach ($rows as $row) {
$form_answer = new PluginFormcreatorForm_Answer();
$form_answer = new PluginFormcreatorFormAnswer();
$form_answer->update([
'id' => $row['id'],
'is_deleted' => 1,
Expand All @@ -361,9 +363,9 @@ function plugin_formcreator_hook_restore_ticket(CommonDBTM $item) {

// Restore deletes form_answers
$item_ticket = new Item_Ticket();
$rows = $item_ticket->find("`itemtype` = 'PluginFormcreatorForm_Answer' AND `tickets_id` = '$id'");
$rows = $item_ticket->find("`itemtype` = 'PluginFormcreatorFormAnswer' AND `tickets_id` = '$id'");
foreach ($rows as $row) {
$form_answer = new PluginFormcreatorForm_Answer();
$form_answer = new PluginFormcreatorFormAnswer();
$form_answer->update([
'id' => $row['id'],
'is_deleted' => 0,
Expand Down Expand Up @@ -401,15 +403,15 @@ function plugin_formcreator_hook_purge_ticket(CommonDBTM $item) {

function plugin_formcreator_dynamicReport($params) {
switch ($params['item_type']) {
case PluginFormcreatorForm_Answer::class;
case PluginFormcreatorFormAnswer::class;
if ($url = parse_url($_SERVER['HTTP_REFERER'])) {
if (strpos($url['path'],
Toolbox::getItemTypeFormURL("PluginFormcreatorForm")) !== false) {
parse_str($url['query'], $query);
if (isset($query['id'])) {
$item = new PluginFormcreatorForm;
$item->getFromDB($query['id']);
PluginFormcreatorForm_Answer::showForForm($item, $params);
PluginFormcreatorFormAnswer::showForForm($item, $params);
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions inc/answer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

class PluginFormcreatorAnswer extends CommonDBChild
{
static public $itemtype = "PluginFormcreatorForm_Answer";
static public $items_id = "plugin_formcreator_forms_answers_id";
static public $itemtype = PluginFormcreatorFormAnswer::class;
static public $items_id = "plugin_formcreator_formanswers_id";

/**
* Check if current user have the right to create and modify requests
Expand Down
2 changes: 1 addition & 1 deletion inc/fields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public static function updateVisibility($input) {
$fields[$id] = PluginFormcreatorFields::getFieldInstance(
$question->fields['fieldtype'],
$question
);
);
$fields[$id]->parseAnswerValues($input);
}

Expand Down
2 changes: 1 addition & 1 deletion inc/fields/filefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private function saveDocument($file, $prefix) {
return;
}

$doc = new Document();
$doc = new Document();
$file_data = [];
$file_data["name"] = Toolbox::addslashes_deep($form->getField('name'). ' - ' . $this->fields['name']);
$file_data["entities_id"] = isset($_SESSION['glpiactive_entity'])
Expand Down
3 changes: 3 additions & 0 deletions inc/fields/textfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ public static function getJSFields() {

public function parseAnswerValues($input) {
$key = 'formcreator_field_' . $this->fields['id'];
if (!isset($input[$key])) {
return false;
}
if (!is_string($input[$key])) {
return false;
}
Expand Down
30 changes: 15 additions & 15 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function canPurgeItem() {
$criteria = [
PluginFormcreatorForm::getForeignKeyField() => $this->getID(),
];
if ($DbUtil->countElementsInTable(PluginFormcreatorForm_Answer::getTable(), $criteria) > 0) {
if ($DbUtil->countElementsInTable(PluginFormcreatorFormAnswer::getTable(), $criteria) > 0) {
return false;
}
return Session::haveRight('entity', UPDATE);
Expand All @@ -104,7 +104,7 @@ static function getMenuContent() {
title="' . __('Import forms', 'formcreator') . '">';
$menu['links']['search'] = PluginFormcreatorFormList::getSearchURL(false);
$menu['links']['config'] = PluginFormcreatorForm::getSearchURL(false);
$menu['links'][$validation_image] = PluginFormcreatorForm_Answer::getSearchURL(false);
$menu['links'][$validation_image] = PluginFormcreatorFormAnswer::getSearchURL(false);
$menu['links'][$import_image] = PluginFormcreatorForm::getFormURL(false)."?import_form=1";

return $menu;
Expand Down Expand Up @@ -581,11 +581,11 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
public function defineTabs($options = []) {
$ong = [];
$this->addDefaultFormTab($ong);
$this->addStandardTab('PluginFormcreatorQuestion', $ong, $options);
$this->addStandardTab('PluginFormcreatorForm_Profile', $ong, $options);
$this->addStandardTab('PluginFormcreatorTarget', $ong, $options);
$this->addStandardTab(PluginFormcreatorQuestion::class, $ong, $options);
$this->addStandardTab(PluginFormcreatorForm_Profile::class, $ong, $options);
$this->addStandardTab(PluginFormcreatorTarget::class, $ong, $options);
$this->addStandardTab(__CLASS__, $ong, $options);
$this->addStandardTab('PluginFormcreatorForm_Answer', $ong, $options);
$this->addStandardTab(PluginFormcreatorFormAnswer::class, $ong, $options);
return $ong;
}

Expand Down Expand Up @@ -825,7 +825,7 @@ protected function showMyLastForms() {
echo '<div class="plugin_formcreator_heading">'.__('My last forms (requester)', 'formcreator').'</div>';
$query = "SELECT fa.`id`, f.`name`, fa.`status`, fa.`request_date`
FROM glpi_plugin_formcreator_forms f
INNER JOIN glpi_plugin_formcreator_forms_answers fa ON f.`id` = fa.`plugin_formcreator_forms_id`
INNER JOIN glpi_plugin_formcreator_formanswers fa ON f.`id` = fa.`plugin_formcreator_forms_id`
WHERE fa.`requester_id` = '$userId'
AND f.is_deleted = 0
ORDER BY fa.`status` ASC, fa.`request_date` DESC
Expand All @@ -837,13 +837,13 @@ protected function showMyLastForms() {
} else {
while ($form = $DB->fetch_assoc($result)) {
echo '<li class="plugin_formcreator_answer">';
echo ' <a class="plugin_formcreator_'.$form['status'].'" href="form_answer.form.php?id='.$form['id'].'">'.$form['name'].'</a>';
echo ' <a class="plugin_formcreator_'.$form['status'].'" href="formanswer.form.php?id='.$form['id'].'">'.$form['name'].'</a>';
echo '<span class="plugin_formcreator_date">'.Html::convDateTime($form['request_date']).'</span>';
echo '</li>';
}
echo "</ul>";
echo '<div align="center">';
echo '<a href="form_answer.php?criteria[0][field]=4&criteria[0][searchtype]=equals&criteria[0][value]='.$userId.'">';
echo '<a href="formanswer.php?criteria[0][field]=4&criteria[0][searchtype]=equals&criteria[0][value]='.$userId.'">';
echo __('All my forms (requester)', 'formcreator');
echo '</a>';
echo '</div>';
Expand All @@ -865,7 +865,7 @@ protected function showMyLastForms() {
$query = "SELECT fa.`id`, f.`name`, fa.`status`, fa.`request_date`
FROM glpi_plugin_formcreator_forms f
INNER JOIN glpi_plugin_formcreator_forms_validators fv ON fv.`plugin_formcreator_forms_id`=f.`id`
INNER JOIN glpi_plugin_formcreator_forms_answers fa ON f.`id` = fa.`plugin_formcreator_forms_id`
INNER JOIN glpi_plugin_formcreator_formanswers fa ON f.`id` = fa.`plugin_formcreator_forms_id`
WHERE (f.`validation_required` = 1 AND fv.`items_id` = '$userId' AND fv.`itemtype` = 'User' AND `fa`.`users_id_validator` = '$userId'
OR f.`validation_required` = 2 AND fv.`items_id` IN ($groupIdListString) AND fv.`itemtype` = 'Group' AND `fa`.`groups_id_validator` IN ($groupIdListString)
)
Expand All @@ -879,7 +879,7 @@ protected function showMyLastForms() {
echo "<ul>";
while ($form = $DB->fetch_assoc($result)) {
echo '<li class="plugin_formcreator_answer">';
echo ' <a class="plugin_formcreator_'.$form['status'].'" href="form_answer.form.php?id='.$form['id'].'">'.$form['name'].'</a>';
echo ' <a class="plugin_formcreator_'.$form['status'].'" href="formanswer.form.php?id='.$form['id'].'">'.$form['name'].'</a>';
echo '<span class="plugin_formcreator_date">'.Html::convDateTime($form['request_date']).'</span>';
echo '</li>';
}
Expand All @@ -891,7 +891,7 @@ protected function showMyLastForms() {
. "&criteria[1][searchtype]=equals"
. "&criteria[1][value]=mygroups";

echo '<a href="form_answer.php?' . $criteria . '">';
echo '<a href="formanswer.php?' . $criteria . '">';
echo __('All my forms (validator)', 'formcreator');
echo '</a>';
echo '</div>';
Expand Down Expand Up @@ -920,7 +920,7 @@ public function displayUserForm() {

// Display form
$formName = 'formcreator_form' . $this->getID();
echo "<form name='" . $formName . "' method='post' role='form' enctype='multipart/form-data'
echo "<form name='form' method='post' role='form' enctype='multipart/form-data'
action='". $CFG_GLPI['root_doc'] . "/plugins/formcreator/front/form.form.php'
class='formcreator_form form_horizontal'>";
echo "<h1 class='form-title'>";
Expand Down Expand Up @@ -966,7 +966,7 @@ class='formcreator_form form_horizontal'>";
}
}
echo Html::scriptBlock('$(function() {
formcreatorShowFields($("form[name=\'' . $formName . '\']"));
formcreatorShowFields($("form[name=\'form\']"));
})');

// Show validator selector
Expand Down Expand Up @@ -1210,7 +1210,7 @@ public function saveForm($input) {
return false;
}

$formanswer = new PluginFormcreatorForm_Answer();
$formanswer = new PluginFormcreatorFormAnswer();
return $formanswer->saveAnswers($this, $input, $fields);
}

Expand Down
Loading

0 comments on commit b2f825b

Please sign in to comment.