/** * Check if a field should be shown or not * * @param Integer $id ID of the current question * @param Array $values Array of current fields values (id => value) * @return boolean Should be shown or not */ public static function isVisible($id, $values) { $question = new PluginFormcreatorQuestion(); $question->getFromDB($id); $fields = $question->fields; $conditions = array(); $return = false; // If the field is always shown if ($fields['show_rule'] == 'always') { return true; } // Get conditions to show or hide field $query = "SELECT `show_logic`, `show_field`, `show_condition`, `show_value`\n FROM `glpi_plugin_formcreator_questions_conditions`\n WHERE `plugin_formcreator_questions_id` = " . (int) $fields['id']; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $conditions[] = array('multiple' => in_array($fields['fieldtype'], array('checkboxes', 'multiselect')), 'logic' => $line['show_logic'], 'field' => $line['show_field'], 'operator' => $line['show_condition'], 'value' => $line['show_value']); } foreach ($conditions as $condition) { if (!isset($values[$condition['field']])) { return false; } if (!self::isVisible($condition['field'], $values)) { return false; } switch ($condition['operator']) { case '!=': if (empty($values[$condition['field']])) { $value = true; } else { if (is_array($values[$condition['field']])) { $value = !in_array($condition['value'], $values[$condition['field']]); } elseif (!is_null(json_decode($values[$condition['field']]))) { $value = !in_array($condition['value'], json_decode($values[$condition['field']])); } else { $value = $condition['value'] != $values[$condition['field']]; } } break; case '==': if (empty($condition['value'])) { $value = false; } else { if (is_array($values[$condition['field']])) { $value = in_array($condition['value'], $values[$condition['field']]); } elseif (!is_null(json_decode($values[$condition['field']]))) { $value = in_array($condition['value'], json_decode($values[$condition['field']])); } else { $value = $condition['value'] == $values[$condition['field']]; } } break; default: if (is_array($values[$condition['field']])) { eval('$value = "' . $condition['value'] . '" ' . $condition['operator'] . ' Array(' . implode(',', $values[$condition['field']]) . ');'); } elseif (!is_null(json_decode($values[$condition['field']]))) { eval('$value = "' . $condition['value'] . '" ' . $condition['operator'] . ' Array(' . implode(',', json_decode($values[$condition['field']])) . ');'); } else { eval('$value = "' . $values[$condition['field']] . '" ' . $condition['operator'] . ' "' . $condition['value'] . '";'); } } switch ($condition['logic']) { case 'AND': $return &= $value; break; case 'OR': $return |= $value; break; case 'XOR': $return ^= $value; break; default: $return = $value; } } // If the field is hidden by default, show it if condition is true if ($question->fields['show_rule'] == 'hidden') { return $return; // else show it if condition is false } else { return !$return; } }
public static function show($field, $datas) { $value = !empty($datas['formcreator_field_' . $field['id']]) ? $datas['formcreator_field_' . $field['id']] : $field['default_values']; if ($field['required']) { $required = ' required'; } else { $required = ''; } $hide = $field['show_type'] == 'hide' ? ' style="display: none"' : ''; echo '<div class="form-group' . $required . '" id="form-group-field' . $field['id'] . '"' . $hide . '>'; echo '<label>'; echo $field['name']; if ($field['required']) { echo ' <span class="red">*</span>'; } echo '</label>'; echo '<input type="text" class="form-control" name="formcreator_field_' . $field['id'] . '" id="formcreator_field_' . $field['id'] . '" value="' . $value . '" />'; echo '<div class="help-block">' . html_entity_decode($field['description']) . '</div>'; switch ($field['show_condition']) { case 'notequal': $condition = '!='; break; case 'lower': $condition = '<'; break; case 'greater': $condition = '>'; break; default: $condition = '=='; break; } if ($field['show_type'] == 'hide') { $conditionnalField = new PluginFormcreatorQuestion(); $conditionnalField->getFromDB($field['show_field']); switch ($conditionnalField->fields['fieldtype']) { case 'checkboxes': echo '<script type="text/javascript"> var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]"); for(var i=0; inputElements[i]; ++i) { inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()}); } function showFormGroup' . $field['id'] . '() { var checkedValue = false; for(var i=0; inputElements[i]; ++i) { if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) { checkedValue = true; } } if(checkedValue) { document.getElementById("form-group-field' . $field['id'] . '").style.display = "block"; } else { document.getElementById("form-group-field' . $field['id'] . '").style.display = "none"; } } showFormGroup' . $field['id'] . '(); </script>'; break; case 'multiselect': echo '<script type="text/javascript"> var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]")[1]; inputElements.addEventListener("change", function(){showFormGroup' . $field['id'] . '()}); function showFormGroup' . $field['id'] . '() { var checkedValue = false; for(var i=0; inputElements[i]; ++i) { if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].selected) { checkedValue = true; } } if(checkedValue) { document.getElementById("form-group-field' . $field['id'] . '").style.display = "block"; } else { document.getElementById("form-group-field' . $field['id'] . '").style.display = "none"; } } showFormGroup' . $field['id'] . '(); </script>'; break; case 'radios': echo '<script type="text/javascript"> var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '"); for(var i=0; inputElements[i]; ++i) { inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()}); } function showFormGroup' . $field['id'] . '() { var checkedValue = false; for(var i=0; inputElements[i]; ++i) { if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) { checkedValue = true; } } if(checkedValue) { document.getElementById("form-group-field' . $field['id'] . '").style.display = "block"; } else { document.getElementById("form-group-field' . $field['id'] . '").style.display = "none"; } } showFormGroup' . $field['id'] . '(); </script>'; break; default: echo '<script type="text/javascript"> document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].addEventListener("change", function(){showFormGroup' . $field['id'] . '()}); function showFormGroup' . $field['id'] . '() { var field_value = document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].value; if(field_value ' . $condition . ' "' . $field['show_value'] . '") { document.getElementById("form-group-field' . $field['id'] . '").style.display = "block"; } else { document.getElementById("form-group-field' . $field['id'] . '").style.display = "none"; } } showFormGroup' . $field['id'] . '(); </script>'; } } echo '</div>' . PHP_EOL; }
<?php include '../../../inc/includes.php'; Session::checkRight("entity", UPDATE); $question = new PluginFormcreatorQuestion(); if (empty($_REQUEST['question_id'])) { $question_id = 0; $question->getEmpty(); } else { $question_id = (int) $_REQUEST['question_id']; $question->getFromDB($question_id); } $form_id = (int) $_REQUEST['form_id']; $rand = mt_rand(); ?> <form name="form_question" method="post" action="<?php echo $GLOBALS['CFG_GLPI']['root_doc']; ?> /plugins/formcreator/front/question.form.php"> <table class="tab_cadre_fixe"> <tr> <th colspan="4"> <?php echo 0 == $question_id ? __('Add a question', 'formcreator') : __('Edit a question', 'formcreator'); ?> </th> </tr>
public static function show($field, $datas) { $default_values = explode("\r\n", $field['default_values']); $default_value = array_shift($default_values); $default_value = !empty($datas['formcreator_field_' . $field['id']]) ? $datas['formcreator_field_' . $field['id']] : $default_value; if ($field['required']) { $required = ' required'; } else { $required = ''; } $hide = $field['show_type'] == 'hide' ? ' style="display: none"' : ''; echo '<div class="form-group' . $required . '" id="form-group-field' . $field['id'] . '"' . $hide . '>'; echo '<label>'; echo $field['name']; if ($field['required']) { echo ' <span class="red">*</span>'; } echo '</label>'; if (!empty($field['values'])) { $ldap_values = json_decode($field['values']); $ldap_dropdown = new RuleRightParameter(); $ldap_dropdown->getFromDB($ldap_values->ldap_attribute); $attribute = array($ldap_dropdown->fields['value']); $config_ldap = new AuthLDAP(); $config_ldap->getFromDB($ldap_values->ldap_auth); if (!function_exists('warning_handler')) { function warning_handler($errno, $errstr, $errfile, $errline, array $errcontext) { if (0 === error_reporting()) { return false; } throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } } set_error_handler("warning_handler", E_WARNING); try { $ds = $config_ldap->connect(); $sn = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute); $entries = ldap_get_entries($ds, $sn); array_shift($entries); $tab_values = array(); foreach ($entries as $id => $attr) { if (isset($attr[$attribute[0]]) && !in_array($attr[$attribute[0]][0], $tab_values)) { $tab_values[$id] = $attr[$attribute[0]][0]; } } if ($field['show_empty']) { $tab_values = array('' => '-----') + $tab_values; } sort($tab_values); Dropdown::showFromArray('formcreator_field_' . $field['id'], $tab_values, array('value' => $default_value)); } catch (Exception $e) { echo '<b><i class="red">'; echo __('Cannot recover LDAP informations!', 'formcreator'); echo '</i></b>'; } restore_error_handler(); } echo '<div class="help-block">' . html_entity_decode($field['description']) . '</div>'; switch ($field['show_condition']) { case 'notequal': $condition = '!='; break; case 'lower': $condition = '<'; break; case 'greater': $condition = '>'; break; default: $condition = '=='; break; } if ($field['show_type'] == 'hide') { $conditionnalField = new PluginFormcreatorQuestion(); $conditionnalField->getFromDB($field['show_field']); switch ($conditionnalField->fields['fieldtype']) { case 'checkboxes': echo '<script type="text/javascript"> var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]"); for(var i=0; inputElements[i]; ++i) { inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()}); } function showFormGroup' . $field['id'] . '() { var checkedValue = false; for(var i=0; inputElements[i]; ++i) { if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) { checkedValue = true; } } if(checkedValue) { document.getElementById("form-group-field' . $field['id'] . '").style.display = "block"; } else { document.getElementById("form-group-field' . $field['id'] . '").style.display = "none"; } } showFormGroup' . $field['id'] . '(); </script>'; break; case 'multiselect': echo '<script type="text/javascript"> var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]")[1]; inputElements.addEventListener("change", function(){showFormGroup' . $field['id'] . '()}); function showFormGroup' . $field['id'] . '() { var checkedValue = false; for(var i=0; inputElements[i]; ++i) { if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].selected) { checkedValue = true; } } if(checkedValue) { document.getElementById("form-group-field' . $field['id'] . '").style.display = "block"; } else { document.getElementById("form-group-field' . $field['id'] . '").style.display = "none"; } } showFormGroup' . $field['id'] . '(); </script>'; break; case 'radios': echo '<script type="text/javascript"> var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '"); for(var i=0; inputElements[i]; ++i) { inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()}); } function showFormGroup' . $field['id'] . '() { var checkedValue = false; for(var i=0; inputElements[i]; ++i) { if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) { checkedValue = true; } } if(checkedValue) { document.getElementById("form-group-field' . $field['id'] . '").style.display = "block"; } else { document.getElementById("form-group-field' . $field['id'] . '").style.display = "none"; } } showFormGroup' . $field['id'] . '(); </script>'; break; default: echo '<script type="text/javascript"> document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].addEventListener("change", function(){showFormGroup' . $field['id'] . '()}); function showFormGroup' . $field['id'] . '() { var field_value = document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].value; if(field_value ' . $condition . ' "' . $field['show_value'] . '") { document.getElementById("form-group-field' . $field['id'] . '").style.display = "block"; } else { document.getElementById("form-group-field' . $field['id'] . '").style.display = "none"; } } showFormGroup' . $field['id'] . '(); </script>'; } } echo '</div>' . PHP_EOL; }
/** * Show the Form edit form the the adminsitrator in the config page * * @param Array $options Optional options * * @return NULL Nothing, just display the form */ public function showForm($options = array()) { $rand = mt_rand(); $obj = new PluginFormcreatorTarget(); $found = $obj->find("itemtype = '" . __CLASS__ . "' AND items_id = " . (int) $this->getID()); $target = array_shift($found); $form = new PluginFormcreatorForm(); $form->getFromDB($target['plugin_formcreator_forms_id']); echo '<div class="center" style="width: 950px; margin: 0 auto;">'; echo '<form name="form_target" method="post" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">'; // General information : name echo '<table class="tab_cadre_fixe">'; echo '<tr><th colspan="2">' . __('Edit a destination', 'formcreator') . '</th></tr>'; echo '<tr class="line1">'; echo '<td width="15%"><strong>' . __('Name') . ' <span style="color:red;">*</span></strong></td>'; echo '<td width="85%"><input type="text" name="name" style="width:704px;" value="' . $target['name'] . '"></textarea</td>'; echo '</tr>'; echo '</table>'; // Ticket information : title, template... echo '<table class="tab_cadre_fixe">'; echo '<tr><th colspan="4">' . _n('Target ticket', 'Target tickets', 1, 'formcreator') . '</th></tr>'; echo '<tr class="line1">'; echo '<td><strong>' . __('Ticket title', 'formcreator') . ' <span style="color:red;">*</span></strong></td>'; echo '<td colspan="3"><input type="text" name="title" style="width:704px;" value="' . $this->fields['name'] . '"></textarea</td>'; echo '</tr>'; echo '<tr class="line0">'; echo '<td><strong>' . __('Description') . ' <span style="color:red;">*</span></strong></td>'; echo '<td colspan="3">'; echo '<textarea name="comment" style="width:700px;" rows="15">' . $this->fields['comment'] . '</textarea>'; if ($GLOBALS['CFG_GLPI']["use_rich_text"]) { Html::initEditorSystem('comment'); } echo '</td>'; echo '</tr>'; // Ticket Template echo '<tr class="line1">'; echo '<td width="15%">' . _n('Ticket template', 'Ticket templates', 1) . '</td>'; echo '<td width="25%">'; Dropdown::show('TicketTemplate', array('name' => 'tickettemplates_id', 'value' => $this->fields['tickettemplates_id'])); echo '</td>'; echo '<td width="15%">' . __('Due date') . '</td>'; echo '<td width="45%">'; // ------------------------------------------------------------------------------------------- // Due date type selection // ------------------------------------------------------------------------------------------- Dropdown::showFromArray('due_date_rule', array('' => Dropdown::EMPTY_VALUE, 'answer' => __('equals to the answer to the question', 'formcreator'), 'ticket' => __('calculated from the ticket creation date', 'formcreator'), 'calcul' => __('calculated from the answer to the question', 'formcreator')), array('value' => $this->fields['due_date_rule'], 'on_change' => 'formcreatorChangeDueDate(this.value)')); // for each section ... $questions_list = array(Dropdown::EMPTY_VALUE); $query = "SELECT s.id, s.name\n FROM glpi_plugin_formcreator_targets t\n INNER JOIN glpi_plugin_formcreator_sections s ON s.plugin_formcreator_forms_id = t.plugin_formcreator_forms_id\n WHERE t.items_id = " . (int) $this->getID() . "\n ORDER BY s.order"; $result = $GLOBALS['DB']->query($query); while ($section = $GLOBALS['DB']->fetch_array($result)) { // select all date and datetime questions $query2 = "SELECT q.id, q.name\n FROM glpi_plugin_formcreator_questions q\n INNER JOIN glpi_plugin_formcreator_sections s ON s.id = q.plugin_formcreator_sections_id\n WHERE s.id = {$section['id']}\n AND q.fieldtype IN ('date', 'datetime')"; $result2 = $GLOBALS['DB']->query($query2); $section_questions = array(); while ($question = $GLOBALS['DB']->fetch_array($result2)) { $section_questions[$question['id']] = $question['name']; } if (count($section_questions) > 0) { $questions_list[$section['name']] = $section_questions; } } // List questions if ($this->fields['due_date_rule'] != 'answer' && $this->fields['due_date_rule'] != 'calcul') { echo '<div id="due_date_questions" style="display:none">'; } else { echo '<div id="due_date_questions">'; } Dropdown::showFromArray('due_date_question', $questions_list, array('value' => $this->fields['due_date_question'])); echo '</div>'; if ($this->fields['due_date_rule'] != 'ticket' && $this->fields['due_date_rule'] != 'calcul') { echo '<div id="due_date_time" style="display:none">'; } else { echo '<div id="due_date_time">'; } Dropdown::showNumber("due_date_value", array('value' => $this->fields['due_date_value'], 'min' => -30, 'max' => 30)); Dropdown::showFromArray('due_date_period', array('minute' => _n('Minute', 'Minutes', 2), 'hour' => _n('Hour', 'Hours', 2), 'day' => _n('Day', 'Days', 2), 'month' => __('Month')), array('value' => $this->fields['due_date_period'])); echo '</div>'; echo '</td>'; echo '</tr>'; // ------------------------------------------------------------------------------------------- // Due date type selection end // ------------------------------------------------------------------------------------------- if ($form->fields['validation_required']) { echo '<tr class="line0">'; echo '<td colspan="4">'; echo '<input type="hidden" name="validation_followup" value="0" />'; echo '<input type="checkbox" name="validation_followup" id="validation_followup" value="1" '; if (!isset($this->fields['validation_followup']) || $this->fields['validation_followup'] == 1) { echo ' checked="checked"'; } echo '/>'; echo ' <label for="validation_followup">'; echo __('Add validation message as first ticket followup', 'formcreator'); echo '</label>'; echo '</td>'; echo '</tr>'; } echo '</table>'; // Buttons echo '<table class="tab_cadre_fixe">'; echo '<tr class="line1">'; echo '<td colspan="5" class="center">'; echo '<input type="reset" name="reset" class="submit_button" value="' . __('Cancel', 'formcreator') . '" onclick="document.location = \'form.form.php?id=' . $target['plugin_formcreator_forms_id'] . '\'" /> '; echo '<input type="hidden" name="id" value="' . $this->getID() . '" />'; echo '<input type="submit" name="update" class="submit_button" value="' . __('Save') . '" />'; echo '</td>'; echo '</tr>'; echo '</table>'; Html::closeForm(); // Get available questions for actors lists $questions_user_list = array(Dropdown::EMPTY_VALUE); $questions_group_list = array(Dropdown::EMPTY_VALUE); $questions_supplier_list = array(Dropdown::EMPTY_VALUE); $query = "SELECT s.id, s.name\n FROM glpi_plugin_formcreator_targets t\n INNER JOIN glpi_plugin_formcreator_sections s ON s.plugin_formcreator_forms_id = t.plugin_formcreator_forms_id\n WHERE t.items_id = " . (int) $this->getID() . "\n ORDER BY s.order"; $result = $GLOBALS['DB']->query($query); while ($section = $GLOBALS['DB']->fetch_array($result)) { // select all user, group or supplier questions (GLPI Object) $query2 = "SELECT q.id, q.name, q.values\n FROM glpi_plugin_formcreator_questions q\n INNER JOIN glpi_plugin_formcreator_sections s ON s.id = q.plugin_formcreator_sections_id\n WHERE s.id = {$section['id']}\n AND q.fieldtype = 'glpiselect'\n AND q.values IN ('User', 'Group', 'Supplier')"; $result2 = $GLOBALS['DB']->query($query2); $section_questions_user = array(); $section_questions_group = array(); $section_questions_supplier = array(); while ($question = $GLOBALS['DB']->fetch_array($result2)) { switch ($question['values']) { case 'User': $section_questions_user[$question['id']] = $question['name']; break; case 'Group': $section_questions_group[$question['id']] = $question['name']; break; case 'Supplier': $section_questions_supplier[$question['id']] = $question['name']; break; } } $questions_user_list[$section['name']] = $section_questions_user; $questions_group_list[$section['name']] = $section_questions_group; $questions_supplier_list[$section['name']] = $section_questions_supplier; } // Get available questions for actors lists $actors = array('requester' => array(), 'observer' => array(), 'assigned' => array()); $query = "SELECT id, actor_role, actor_type, actor_value, use_notification\n FROM glpi_plugin_formcreator_targettickets_actors\n WHERE plugin_formcreator_targettickets_id = " . $this->getID(); $result = $GLOBALS['DB']->query($query); while ($actor = $GLOBALS['DB']->fetch_array($result)) { $actors[$actor['actor_role']][$actor['id']] = array('actor_type' => $actor['actor_type'], 'actor_value' => $actor['actor_value'], 'use_notification' => $actor['use_notification']); } $img_user = '******' . __('User') . '" title="' . __('User') . '" width="20" />'; $img_group = '<img src="../../../pics/groupes.png" alt="' . __('Group') . '" title="' . __('Group') . '" width="20" />'; $img_supplier = '<img src="../../../pics/supplier.png" alt="' . __('Supplier') . '" title="' . __('Supplier') . '" width="20" />'; $img_mail = '<img src="../pics/email.png" alt="' . __('Yes') . '" title="' . __('Email followup') . ' ' . __('Yes') . '" />'; $img_nomail = '<img src="../pics/email-no.png" alt="' . __('No') . '" title="' . __('Email followup') . ' ' . __('No') . '" />'; echo '<table class="tab_cadre_fixe">'; echo '<tr><th colspan="3">' . __('Ticket actors', 'formcreator') . '</th></tr>'; echo '<tr>'; echo '<th width="33%">'; echo _n('Requester', 'Requesters', 1) . ' '; echo '<img title="Ajouter" alt="Ajouter" onclick="displayRequesterForm()" class="pointer" id="btn_add_requester" src="../../../pics/add_dropdown.png">'; echo '<img title="Annuler" alt="Annuler" onclick="hideRequesterForm()" class="pointer" id="btn_cancel_requester" src="../../../pics/delete.png" style="display:none">'; echo '</th>'; echo '<th width="34%">'; echo _n('Watcher', 'Watchers', 1) . ' '; echo '<img title="Ajouter" alt="Ajouter" onclick="displayWatcherForm()" class="pointer" id="btn_add_watcher" src="../../../pics/add_dropdown.png">'; echo '<img title="Annuler" alt="Annuler" onclick="hideWatcherForm()" class="pointer" id="btn_cancel_watcher" src="../../../pics/delete.png" style="display:none">'; echo '</th>'; echo '<th width="33%">'; echo __('Assigned to') . ' '; echo '<img title="Ajouter" alt="Ajouter" onclick="displayAssignedForm()" class="pointer" id="btn_add_assigned" src="../../../pics/add_dropdown.png">'; echo '<img title="Annuler" alt="Annuler" onclick="hideAssignedForm()" class="pointer" id="btn_cancel_assigned" src="../../../pics/delete.png" style="display:none">'; echo '</th>'; echo '</tr>'; echo '<tr>'; // Requester echo '<td valign="top">'; // => Add requester form echo '<form name="form_target" id="form_add_requester" method="post" style="display:none" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">'; Dropdown::showFromArray('actor_type', array('' => Dropdown::EMPTY_VALUE, 'creator' => __('Form requester', 'formcreator'), 'validator' => __('Form validator', 'formcreator'), 'person' => __('Specific person', 'formcreator'), 'question_person' => __('Person from the question', 'formcreator'), 'group' => __('Specific group', 'formcreator'), 'question_group' => __('Group from the question', 'formcreator')), array('on_change' => 'formcreatorChangeActorRequester(this.value)')); echo '<div id="block_requester_user" style="display:none">'; User::dropdown(array('name' => 'actor_value_person', 'right' => 'all', 'all' => 0)); echo '</div>'; echo '<div id="block_requester_group" style="display:none">'; Group::dropdown(array('name' => 'actor_value_group')); echo '</div>'; echo '<div id="block_requester_question_user" style="display:none">'; Dropdown::showFromArray('actor_value_question_person', $questions_user_list, array('value' => $this->fields['due_date_question'])); echo '</div>'; echo '<div id="block_requester_question_group" style="display:none">'; Dropdown::showFromArray('actor_value_question_group', $questions_group_list, array('value' => $this->fields['due_date_question'])); echo '</div>'; echo '<div>'; echo __('Email followup'); Dropdown::showYesNo('use_notification', 1); echo '</div>'; echo '<p align="center">'; echo '<input type="hidden" name="id" value="' . $this->getID() . '" />'; echo '<input type="hidden" name="actor_role" value="requester" />'; echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />'; echo '</p>'; echo "<hr>"; Html::closeForm(); // => List of saved requesters foreach ($actors['requester'] as $id => $values) { echo '<div>'; switch ($values['actor_type']) { case 'creator': echo $img_user . ' <b>' . __('Form requester', 'formcreator') . '</b>'; break; case 'validator': echo $img_user . ' <b>' . __('Form validator', 'formcreator') . '</b>'; break; case 'person': $user = new User(); $user->getFromDB($values['actor_value']); echo $img_user . ' <b>' . __('User') . ' </b> "' . $user->getName() . '"'; break; case 'question_person': $question = new PluginFormcreatorQuestion(); $question->getFromDB($values['actor_value']); echo $img_user . ' <b>' . __('Person from the question', 'formcreator') . '</b> "' . $question->getName() . '"'; break; case 'group': $group = new Group(); $group->getFromDB($values['actor_value']); echo $img_user . ' <b>' . __('Group') . ' </b> "' . $group->getName() . '"'; break; case 'question_group': $question = new PluginFormcreatorQuestion(); $question->getFromDB($values['actor_value']); echo $img_group . ' <b>' . __('Group from the question', 'formcreator') . '</b> "' . $question->getName() . '"'; break; } echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' '; echo self::getDeleteImage($id); echo '</div>'; } echo '</td>'; // Observer echo '<td valign="top">'; // => Add observer form echo '<form name="form_target" id="form_add_watcher" method="post" style="display:none" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">'; Dropdown::showFromArray('actor_type', array('' => Dropdown::EMPTY_VALUE, 'creator' => __('Form requester', 'formcreator'), 'validator' => __('Form validator', 'formcreator'), 'person' => __('Specific person', 'formcreator'), 'question_person' => __('Person from the question', 'formcreator'), 'group' => __('Specific group', 'formcreator'), 'question_group' => __('Group from the question', 'formcreator')), array('on_change' => 'formcreatorChangeActorWatcher(this.value)')); echo '<div id="block_watcher_user" style="display:none">'; User::dropdown(array('name' => 'actor_value_person', 'right' => 'all', 'all' => 0)); echo '</div>'; echo '<div id="block_watcher_group" style="display:none">'; Group::dropdown(array('name' => 'actor_value_group')); echo '</div>'; echo '<div id="block_watcher_question_user" style="display:none">'; Dropdown::showFromArray('actor_value_question_person', $questions_user_list, array('value' => $this->fields['due_date_question'])); echo '</div>'; echo '<div id="block_watcher_question_group" style="display:none">'; Dropdown::showFromArray('actor_value_question_group', $questions_group_list, array('value' => $this->fields['due_date_question'])); echo '</div>'; echo '<div>'; echo __('Email followup'); Dropdown::showYesNo('use_notification', 1); echo '</div>'; echo '<p align="center">'; echo '<input type="hidden" name="id" value="' . $this->getID() . '" />'; echo '<input type="hidden" name="actor_role" value="observer" />'; echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />'; echo '</p>'; echo "<hr>"; Html::closeForm(); // => List of saved observers foreach ($actors['observer'] as $id => $values) { echo '<div>'; switch ($values['actor_type']) { case 'creator': echo $img_user . ' <b>' . __('Form requester', 'formcreator') . '</b>'; break; case 'validator': echo $img_user . ' <b>' . __('Form validator', 'formcreator') . '</b>'; break; case 'person': $user = new User(); $user->getFromDB($values['actor_value']); echo $img_user . ' <b>' . __('User') . ' </b> "' . $user->getName() . '"'; break; case 'question_person': $question = new PluginFormcreatorQuestion(); $question->getFromDB($values['actor_value']); echo $img_user . ' <b>' . __('Person from the question', 'formcreator') . '</b> "' . $question->getName() . '"'; break; case 'group': $group = new Group(); $group->getFromDB($values['actor_value']); echo $img_user . ' <b>' . __('Group') . ' </b> "' . $group->getName() . '"'; break; case 'question_group': $question = new PluginFormcreatorQuestion(); $question->getFromDB($values['actor_value']); echo $img_group . ' <b>' . __('Group from the question', 'formcreator') . '</b> "' . $question->getName() . '"'; break; } echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' '; echo self::getDeleteImage($id); echo '</div>'; } echo '</td>'; // Assigned to echo '<td valign="top">'; // => Add assigned to form echo '<form name="form_target" id="form_add_assigned" method="post" style="display:none" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">'; Dropdown::showFromArray('actor_type', array('' => Dropdown::EMPTY_VALUE, 'creator' => __('Form requester', 'formcreator'), 'validator' => __('Form validator', 'formcreator'), 'person' => __('Specific person', 'formcreator'), 'question_person' => __('Person from the question', 'formcreator'), 'group' => __('Specific group', 'formcreator'), 'question_group' => __('Group from the question', 'formcreator'), 'supplier' => __('Specific supplier', 'formcreator'), 'question_supplier' => __('Supplier from the question', 'formcreator')), array('on_change' => 'formcreatorChangeActorAssigned(this.value)')); echo '<div id="block_assigned_user" style="display:none">'; User::dropdown(array('name' => 'actor_value_person', 'right' => 'all', 'all' => 0)); echo '</div>'; echo '<div id="block_assigned_group" style="display:none">'; Group::dropdown(array('name' => 'actor_value_group')); echo '</div>'; echo '<div id="block_assigned_supplier" style="display:none">'; Supplier::dropdown(array('name' => 'actor_value_supplier')); echo '</div>'; echo '<div id="block_assigned_question_user" style="display:none">'; Dropdown::showFromArray('actor_value_question_person', $questions_user_list, array('value' => $this->fields['due_date_question'])); echo '</div>'; echo '<div id="block_assigned_question_group" style="display:none">'; Dropdown::showFromArray('actor_value_question_group', $questions_group_list, array('value' => $this->fields['due_date_question'])); echo '</div>'; echo '<div id="block_assigned_question_supplier" style="display:none">'; Dropdown::showFromArray('actor_value_question_supplier', $questions_supplier_list, array('value' => $this->fields['due_date_question'])); echo '</div>'; echo '<div>'; echo __('Email followup'); Dropdown::showYesNo('use_notification', 1); echo '</div>'; echo '<p align="center">'; echo '<input type="hidden" name="id" value="' . $this->getID() . '" />'; echo '<input type="hidden" name="actor_role" value="assigned" />'; echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />'; echo '</p>'; echo "<hr>"; Html::closeForm(); // => List of saved assigned to foreach ($actors['assigned'] as $id => $values) { echo '<div>'; switch ($values['actor_type']) { case 'creator': echo $img_user . ' <b>' . __('Form requester', 'formcreator') . '</b>'; break; case 'validator': echo $img_user . ' <b>' . __('Form validator', 'formcreator') . '</b>'; break; case 'person': $user = new User(); $user->getFromDB($values['actor_value']); echo $img_user . ' <b>' . __('User') . ' </b> "' . $user->getName() . '"'; break; case 'question_person': $question = new PluginFormcreatorQuestion(); $question->getFromDB($values['actor_value']); echo $img_user . ' <b>' . __('Person from the question', 'formcreator') . '</b> "' . $question->getName() . '"'; break; case 'group': $group = new Group(); $group->getFromDB($values['actor_value']); echo $img_user . ' <b>' . __('Group') . ' </b> "' . $group->getName() . '"'; break; case 'question_group': $question = new PluginFormcreatorQuestion(); $question->getFromDB($values['actor_value']); echo $img_group . ' <b>' . __('Group from the question', 'formcreator') . '</b> "' . $question->getName() . '"'; break; case 'supplier': $group = new Group(); $group->getFromDB($values['actor_value']); echo $img_supplier . ' <b>' . __('Supplier') . ' </b> "' . $group->getName() . '"'; break; case 'question_supplier': $question = new PluginFormcreatorQuestion(); $question->getFromDB($values['actor_value']); echo $img_supplier . ' <b>' . __('Supplier from the question', 'formcreator') . '</b> "' . $question->getName() . '"'; break; } echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' '; echo self::getDeleteImage($id); echo '</div>'; } echo '</td>'; echo '</tr>'; echo '</table>'; // List of available tags echo '<table class="tab_cadre_fixe">'; echo '<tr><th colspan="5">' . __('List of available tags') . '</th></tr>'; echo '<tr>'; echo '<th width="40%" colspan="2">' . _n('Question', 'Questions', 1, 'formcreator') . '</th>'; echo '<th width="20%">' . __('Title') . '</th>'; echo '<th width="20%">' . _n('Answer', 'Answers', 1, 'formcreator') . '</th>'; echo '<th width="20%">' . _n('Section', 'Sections', 1, 'formcreator') . '</th>'; echo '</tr>'; echo '<tr class="line0">'; echo '<td colspan="2"><strong>' . __('Full form', 'formcreator') . '</strong></td>'; echo '<td align="center"><code>-</code></td>'; echo '<td align="center"><code><strong>##FULLFORM##</strong></code></td>'; echo '<td align="center">-</td>'; echo '</tr>'; $table_questions = getTableForItemType('PluginFormcreatorQuestion'); $table_sections = getTableForItemType('PluginFormcreatorSection'); $query = "SELECT q.`id`, q.`name` AS question, s.`name` AS section\n FROM {$table_questions} q\n LEFT JOIN {$table_sections} s ON q.`plugin_formcreator_sections_id` = s.`id`\n WHERE s.`plugin_formcreator_forms_id` = " . $target['plugin_formcreator_forms_id'] . "\n ORDER BY s.`order`, q.`order`"; $result = $GLOBALS['DB']->query($query); $i = 0; while ($question = $GLOBALS['DB']->fetch_array($result)) { $i++; echo '<tr class="line' . $i % 2 . '">'; echo '<td colspan="2">' . $question['question'] . '</td>'; echo '<td align="center"><code>##question_' . $question['id'] . '##</code></td>'; echo '<td align="center"><code>##answer_' . $question['id'] . '##</code></td>'; echo '<td align="center">' . $question['section'] . '</td>'; echo '</tr>'; } echo '</table>'; echo '</div>'; }
public function saveToTargets($datas) { $valid = true; // Validate form fields foreach ($_POST as $key => $value) { if (substr($key, 0, 18) == 'formcreator_field_') { $question_id = (int) substr($key, 18); $question = new PluginFormcreatorQuestion(); $question->getFromDB($question_id); $className = $question->fields['fieldtype'] . 'Field'; $filePath = dirname(__FILE__) . '/fields/' . $question->fields['fieldtype'] . '-field.class.php'; if ($question->fields['fieldtype'] == 'float') { $value = str_replace(',', '.', $datas['formcreator_field_' . $question_id]); $datas['formcreator_field_' . $question_id] = $value; } if (is_file($filePath)) { include_once $filePath; if (class_exists($className)) { if (!$className::isValid($question->fields, $value, $datas)) { $valid = false; } } } else { $valid = false; } } } // If not valid back to form if (!$valid) { $_SESSION['formcreator']['datas'] = $datas; Html::back(); // Otherwize generate targets } else { $_SESSION['formcreator_documents'] = array(); // Save files as Documents foreach ($_FILES as $question_name => $file) { if (isset($file['tmp_name']) && is_file($file['tmp_name'])) { $doc = new Document(); $question_id = trim(strrchr($question_name, '_'), '_'); $question = new PluginFormcreatorQuestion(); $question->getFromDB($question_id); $file_datas = array(); $file_datas["name"] = $this->fields['name'] . ' - ' . $question->fields['name']; $file_datas["entities_id"] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $this->fields['entities_id']; $file_datas["is_recursive"] = $this->fields['is_recursive']; Document::uploadDocument($file_datas, $file); if ($docID = $doc->add($file_datas)) { $_SESSION['formcreator_documents'][] = $docID; $table = getTableForItemType('Document'); $query = "UPDATE {$table} SET filename = '" . addslashes($file['name']) . "' WHERE id = " . $docID; $GLOBALS['DB']->query($query); } } } // Get all targets $target_class = new PluginFormcreatorTarget(); $founded_targets = $target_class->find('plugin_formcreator_forms_id = ' . $this->getID()); foreach ($founded_targets as $target) { $obj = new $target['itemtype'](); $obj->getFromDB($target['items_id']); $obj->save($this, $datas); } Session::addMessageAfterRedirect(__('The form have been successfully saved!', 'formcreator'), true, INFO); unset($_SESSION['formcreator_documents']); } }