Ejemplo n.º 1
0
function plugin_formcreator_postinit()
{
    global $CFG_GLPI, $PLUGIN_HOOKS;
    foreach (PluginFormcreatorForm::getTypes(true) as $type) {
        CommonGLPI::registerStandardTab($type, 'PluginFormcreatorForm');
    }
}
 public function getSpecificTargets($data, $options)
 {
     switch ($data['items_id']) {
         case self::AUTHOR:
             $this->getUserByField('requester_id', true);
             break;
         case self::APPROVER:
             $form = new PluginFormcreatorForm();
             $form->getFromDB($this->obj->fields['plugin_formcreator_forms_id']);
             if ($form->fields['validation_required'] == 1) {
                 $this->getUserByField('validator_id', true);
             } elseif ($form->fields['validation_required'] == 2) {
                 $this->getAddressesByGroup(0, $this->obj->fields['validator_id']);
             }
             break;
     }
 }
 public function getDatasForTemplate($event, $options = array())
 {
     $form = new PluginFormcreatorForm();
     $form->getFromDB($this->obj->fields['plugin_formcreator_forms_id']);
     $link = 'http://' . $_SERVER['SERVER_NAME'] . $GLOBALS['CFG_GLPI']['root_doc'];
     $link .= '/plugins/formcreator/front/formanswer.form.php?id=' . $this->obj->getID();
     $requester = new User();
     $requester->getFromDB($this->obj->fields['requester_id']);
     $validator = new User();
     $validator->getFromDB($this->obj->fields['validator_id']);
     $this->datas['##formcreator.form_id##'] = $form->getID();
     $this->datas['##formcreator.form_name##'] = $form->fields['name'];
     $this->datas['##formcreator.form_requester##'] = $requester->getName();
     $this->datas['##formcreator.form_validator##'] = $validator->getName();
     $this->datas['##formcreator.form_creation_date##'] = Html::convDateTime($this->obj->fields['request_date']);
     $this->datas['##formcreator.form_full_answers##'] = $this->obj->getFullForm();
     $this->datas['##formcreator.validation_comment##'] = $this->obj->fields['comment'];
     $this->datas['##formcreator.validation_link##'] = $link;
     $this->datas['##formcreator.request_id##'] = $this->obj->fields['id'];
 }
Ejemplo n.º 4
0
 static function getMenuContent()
 {
     global $CFG_GLPI;
     $menu = parent::getMenuContent();
     $image = '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/formcreator/pics/check.png"
               title="' . __('Forms waiting for validation', 'formcreator') . '"
               alt="' . __('Forms waiting for validation', 'formcreator') . '">';
     $menu['links']['search'] = PluginFormcreatorFormList::getSearchURL(false);
     $menu['links']['config'] = PluginFormcreatorForm::getSearchURL(false);
     $menu['links'][$image] = PluginFormcreatorFormanswer::getSearchURL(false);
     return $menu;
 }
        Html::back();
    } elseif (isset($_POST['actor_role'])) {
        Session::checkRight("entity", UPDATE);
        $id = (int) $_POST['id'];
        $actor_value = isset($_POST['actor_value_' . $_POST['actor_type']]) ? $_POST['actor_value_' . $_POST['actor_type']] : '';
        $use_notification = $_POST['use_notification'] == 0 ? 0 : 1;
        $query = "INSERT INTO glpi_plugin_formcreator_targettickets_actors SET\n                  `plugin_formcreator_targettickets_id` = {$id},\n                  `actor_role`                          = '" . $_POST['actor_role'] . "',\n                  `actor_type`                          = '" . $_POST['actor_type'] . "',\n                  `actor_value`                         = " . (int) $actor_value . ",\n                  `use_notification`                    = " . (int) $use_notification;
        $DB->query($query);
        Html::back();
    } elseif (isset($_GET['delete_actor'])) {
        $query = "DELETE FROM glpi_plugin_formcreator_targettickets_actors\n                WHERE id = " . (int) $_GET['delete_actor'];
        $DB->query($query);
        Html::back();
        // Show target ticket form
    } else {
        Html::header(__('Form Creator', 'formcreator'), $_SERVER['PHP_SELF'], 'admin', 'PluginFormcreatorForm');
        $itemtype = "PluginFormcreatorTargetTicket";
        $target = new PluginFormcreatorTarget();
        $found = $target->find("itemtype = '{$itemtype}' AND items_id = " . (int) $_REQUEST['id']);
        $first = array_shift($found);
        $form = new PluginFormcreatorForm();
        $form->getFromDB($first['plugin_formcreator_forms_id']);
        $_SESSION['glpilisttitle'][$itemtype] = sprintf(__('%1$s = %2$s'), $form->getTypeName(1), $form->getName());
        $_SESSION['glpilisturl'][$itemtype] = $form->getFormURL() . "?id=" . $form->getID();
        $targetticket->display($_REQUEST);
        Html::footer();
    }
    // Or display a "Not found" error
} else {
    Html::displayNotFoundError();
}
Ejemplo n.º 6
0
 static function getHomeHelpdeskListForm()
 {
     global $LANG, $CFG_GLPI;
     $form = new PluginFormcreatorForm();
     $listForm = $form->find("is_active = '1'");
     echo "<table style='float: right;'>";
     echo "<tr><td class='top' width='450px'>";
     echo '<table class="tab_cadrehov">';
     echo '<tr>';
     echo '<th>';
     echo '<div class="relative">' . $LANG['plugin_formcreator']["headings"][6] . '</div>';
     echo '</th>';
     echo '</tr>';
     $nbForm = 0;
     foreach ($listForm as $form_id => $value) {
         $question = new PluginFormcreatorQuestion();
         $listQuestion = $question->find("plugin_formcreator_forms_id = '" . $form_id . "'");
         if (!empty($listQuestion)) {
             if (Session::haveAccessToEntity($value['entities_id'], $value['is_recursive'])) {
                 $link = $CFG_GLPI["root_doc"] . "/plugins/formcreator/front/form.helpdesk.php";
                 echo "<tr>";
                 echo '<td><a href=' . $link . '?form=' . $form_id . '>' . $value['name'] . '</a></td>';
                 echo "</tr>";
                 $nbForm++;
             }
         }
     }
     if (!$nbForm) {
         echo '<tr>';
         echo '<td class="center" colspan="3">' . $LANG['plugin_formcreator']["helpdesk"][1] . '</td>';
         echo '</tr>';
     }
     echo '</table>';
     echo "</td></tr>";
     echo "</table>";
 }
 /**
  * Save form datas to the target
  *
  * @param  PluginFormcreatorFormanswer $formanswer    Answers previously saved
  */
 public function save(PluginFormcreatorFormanswer $formanswer)
 {
     $datas = array();
     $ticket = new Ticket();
     $docItem = new Document_Item();
     $form = new PluginFormcreatorForm();
     $form->getFromDB($formanswer->fields['plugin_formcreator_forms_id']);
     // Get default request type
     $query = "SELECT id FROM `glpi_requesttypes` WHERE `name` LIKE 'Formcreator';";
     $result = $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error());
     list($requesttypes_id) = $GLOBALS['DB']->fetch_array($result);
     $datas['requesttypes_id'] = $requesttypes_id;
     // Get predefined Fields
     $ttp = new TicketTemplatePredefinedField();
     $predefined_fields = $ttp->getPredefinedFields($this->fields['tickettemplates_id'], true);
     $datas = array_merge($datas, $predefined_fields);
     // Parse datas and tags
     $datas['name'] = addslashes($this->parseTags($this->fields['name'], $formanswer));
     $datas['content'] = htmlentities($this->parseTags($this->fields['comment'], $formanswer));
     $datas['entities_id'] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id'];
     $datas['_users_id_requester'] = 0;
     $datas['_users_id_recipient'] = $_SESSION['glpiID'];
     $datas['_tickettemplates_id'] = $this->fields['tickettemplates_id'];
     // Define due date
     $answer = new PluginFormcreatorAnswer();
     $found = $answer->find('plugin_formcreator_formanwers_id = ' . (int) $formanswer->fields['id'] . ' AND plugin_formcreator_question_id = ' . (int) $this->fields['due_date_question']);
     $date = array_shift($found);
     $str = "+" . $this->fields['due_date_value'] . " " . $this->fields['due_date_period'];
     switch ($this->fields['due_date_rule']) {
         case 'answer':
             $due_date = $date['answer'];
             break;
         case 'ticket':
             $due_date = date('Y-m-d H:i:s', strtotime($str));
             break;
         case 'calcul':
             $due_date = date('Y-m-d H:i:s', strtotime($date['answer'] . " " . $str));
             break;
         default:
             $due_date = null;
             break;
     }
     if (!is_null($due_date)) {
         $datas['due_date'] = $due_date;
     }
     // Select ticket actors
     $query = "SELECT id, actor_type, actor_value, use_notification\n                FROM glpi_plugin_formcreator_targettickets_actors\n                WHERE plugin_formcreator_targettickets_id = " . $this->getID() . "\n                AND actor_role = 'requester'";
     $result = $GLOBALS['DB']->query($query);
     // If there is only one requester add it on creation, otherwize we will add them later
     if ($GLOBALS['DB']->numrows($result) == 1) {
         $actor = $GLOBALS['DB']->fetch_array($result);
         switch ($actor['actor_type']) {
             case 'creator':
                 $user_id = $formanswer->fields['requester_id'];
                 break;
             case 'validator':
                 $user_id = $formanswer->fields['validator_id'];
                 break;
             case 'person':
             case 'group':
             case 'supplier':
                 $user_id = $actor['actor_value'];
                 break;
             case 'question_person':
             case 'question_group':
             case 'question_supplier':
                 $answer = new PluginFormcreatorAnswer();
                 $found = $answer->find('`plugin_formcreator_question_id` = ' . (int) $actor['actor_value'] . ' AND `plugin_formcreator_formanwers_id` = ' . (int) $formanswer->fields['id']);
                 $found = array_shift($found);
                 if (empty($found['answer'])) {
                     continue;
                 } else {
                     $user_id = (int) $found['answer'];
                 }
                 break;
         }
         $datas['_users_id_requester'] = $user_id;
     }
     // Create the target ticket
     if (!($ticketID = $ticket->add($datas))) {
         return false;
     }
     // Add link between Ticket and FormAnswer
     $itemlink = new Item_Ticket();
     $itemlink->add(array('itemtype' => 'PluginFormcreatorFormanswer', 'items_id' => $formanswer->fields['id'], 'tickets_id' => $ticketID));
     // Add actors to ticket
     $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)) {
         // If actor type is validator and if the form doesn't have a validator, continue to other actors
         if ($actor['actor_type'] == 'validator' && !$form->fields['validation_required']) {
             continue;
         }
         switch ($actor['actor_role']) {
             case 'requester':
                 $role = CommonITILActor::REQUESTER;
                 break;
             case 'observer':
                 $role = CommonITILActor::OBSERVER;
                 break;
             case 'assigned':
                 $role = CommonITILActor::ASSIGN;
                 break;
         }
         switch ($actor['actor_type']) {
             case 'creator':
                 $user_id = $formanswer->fields['requester_id'];
                 break;
             case 'validator':
                 $user_id = $formanswer->fields['validator_id'];
                 break;
             case 'person':
             case 'group':
             case 'supplier':
                 $user_id = $actor['actor_value'];
                 break;
             case 'question_person':
             case 'question_group':
             case 'question_supplier':
                 $answer = new PluginFormcreatorAnswer();
                 $found = $answer->find('`plugin_formcreator_question_id` = ' . (int) $actor['actor_value'] . ' AND `plugin_formcreator_formanwers_id` = ' . (int) $formanswer->fields['id']);
                 $found = array_shift($found);
                 if (empty($found['answer'])) {
                     continue;
                 } else {
                     $user_id = (int) $found['answer'];
                 }
                 break;
         }
         switch ($actor['actor_type']) {
             case 'creator':
             case 'validator':
             case 'person':
             case 'question_person':
                 $obj = new Ticket_User();
                 $obj->add(array('tickets_id' => $ticketID, 'users_id' => $user_id, 'type' => $role, 'use_notification' => $actor['use_notification']));
                 break;
             case 'group':
             case 'question_group':
                 $obj = new Group_Ticket();
                 $obj->add(array('tickets_id' => $ticketID, 'groups_id' => $user_id, 'type' => $role, 'use_notification' => $actor['use_notification']));
                 break;
             case 'supplier':
             case 'question_supplier':
                 $obj = new Supplier_Ticket();
                 $obj->add(array('tickets_id' => $ticketID, 'suppliers_id' => $user_id, 'type' => $role, 'use_notification' => $actor['use_notification']));
                 break;
         }
     }
     // Attach documents to ticket
     $found = $docItem->find("itemtype = 'PluginFormcreatorFormanswer' AND items_id = " . (int) $formanswer->getID());
     if (count($found) > 0) {
         foreach ($found as $document) {
             $docItem->add(array('documents_id' => $document['documents_id'], 'itemtype' => 'Ticket', 'items_id' => $ticketID));
         }
     }
     // Attach validation message as first ticket followup if validation is required and
     // if is set in ticket target configuration
     // /!\ Followup is directly saved to the database to avoid double notification on ticket
     //     creation and add followup
     if ($form->fields['validation_required'] && $this->fields['validation_followup']) {
         $message = addslashes(__('Your form have been accepted by the validator', 'formcreator'));
         if (!empty($formanswer->fields['comment'])) {
             $message .= "\n" . addslashes($formanswer->fields['comment']);
         }
         $query = "INSERT INTO `glpi_ticketfollowups` SET\n                     `tickets_id` = {$ticketID},\n                     `date`       = NOW(),\n                     `users_id`   = {$_SESSION['glpiID']},\n                     `content`    = \"{$message}\"";
         $GLOBALS['DB']->query($query);
     }
     return true;
 }
Ejemplo n.º 8
0
<?php

require_once '../../../inc/includes.php';
// Check if current user have config right
Session::checkRight("entity", UPDATE);
// Check if plugin is activated...
$plugin = new Plugin();
if (!$plugin->isInstalled('formcreator') || !$plugin->isActivated('formcreator')) {
    Html::displayNotFoundError();
}
if (PluginFormcreatorForm::canView()) {
    Html::header(__('Form Creator', 'formcreator'), $_SERVER['PHP_SELF'], 'admin', 'PluginFormcreatorForm');
    Search::show('PluginFormcreatorForm');
    Html::footer();
} else {
    Html::displayRightError();
}
<?php

include '../../../inc/includes.php';
Session::checkRight("config", "w");
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    if (isset($_POST["profiles_id"]) && isset($_POST["form_id"])) {
        if (isset($_POST['access_rights'])) {
            $form = new PluginFormcreatorForm();
            $form->update(array('id' => $_POST['form_id'], 'access_rights' => $_POST['access_rights']));
        }
        $table = getTableForItemType('PluginFormcreatorFormprofiles');
        $DB->query("DELETE FROM {$table} WHERE plugin_formcreator_forms_id = " . (int) $_POST["form_id"]);
        foreach ($_POST["profiles_id"] as $profile_id) {
            if ($profile_id != 0) {
                $query = "INSERT IGNORE INTO {$table} SET\n                        `plugin_formcreator_forms_id` = " . (int) $_POST["form_id"] . ",\n                        `plugin_formcreator_profiles_id` = " . (int) $profile_id;
                $DB->query($query);
            }
        }
        Html::back();
    } else {
        Html::back();
    }
    // Or display a "Not found" error
} else {
    Html::displayNotFoundError();
}
Ejemplo n.º 10
0
<?php

include "../../../inc/includes.php";
Session::checkLoginUser();
$Plugin = new PluginFormcreatorForm();
$PluginItem = new PluginFormcreatorForm_Item();
if (isset($_POST["add"])) {
} else {
    if (isset($_POST["agregarGrupo"])) {
        $listForm = $PluginItem->find("plugin_formcreator_forms_id = " . $_POST['peticion_id'] . " and items_id = " . $_POST['groups_id'] . " and itemtype = '" . $_POST['itemtype'] . "'");
        if (empty($listForm)) {
            $input11 = array('plugin_formcreator_forms_id' => $_POST['peticion_id'], 'items_id' => $_POST['groups_id'], 'itemtype' => $_POST['itemtype']);
            $PluginItem->add($input11);
        }
        Html::back();
    } else {
        Html::header(PluginFormcreatorForm::getTypeName(2), $_SERVER['PHP_SELF'], 'plugins', 'formcreator', 'form');
        $form->display($_GET);
        //$form->showForm($_REQUEST["id"]);
        Html::footer();
    }
}
Ejemplo n.º 11
0
                // Do IF
                $string = preg_replace($regex_if, "\\1", $string, 1);
                $string = preg_replace($regex_else, "", $string, 1);
            } else {
                // Do ELSE
                $string = preg_replace($regex_if, "", $string, 1);
                $string = preg_replace($regex_else, "\\1", $string, 1);
            }
        }
    }
    return $string;
}
echo "<div class='center'>" . "\n\r";
$helpdesk = new PluginFormcreatorHelpdesk();
$formID = $_REQUEST['id'];
$form = new PluginFormcreatorForm();
$form->getFromDB($formID);
$tableau_beneficiary_name = "";
$targets = $helpdesk->getTarget($formID);
foreach ($targets as $target_id => $target_value) {
    $ticket = array();
    $validation_exist = false;
    $validationTab = array();
    $cpt_valid = 0;
    $ticket['entities_id'] = $form->fields['entities_id'];
    $ticket['urgency'] = $target_value['urgency'];
    $ticket['priority'] = $target_value['priority'];
    $ticket['itilcategories_id'] = $target_value['itilcategories_id'];
    $ticket['name'] = $target_value['name'];
    $questions = $helpdesk->getQuestionByForm($formID);
    foreach ($questions as $question_id => $question_value) {
Ejemplo n.º 12
0
<?php

include '../../../inc/includes.php';
//anonyme or not ?
Session::checkLoginUser();
if (Session::getLoginUserID()) {
    Html::header($LANG['plugin_formcreator']['name'], $_SERVER['PHP_SELF'], "plugins", "formcreator", "form");
} else {
    //$_SESSION["glpilanguage"] = $CFG_GLPI['language'];
    Html::simpleHeader($LANG['plugin_formcreator']['name2'], array(__('Authentication') => "../../../index.php?co=1", __('FAQ') => "../../../front/helpdesk.faq.php", $LANG['plugin_formcreator']['name2'] => "./formlist.php"));
}
PluginFormcreatorForm::getHelpdeskListForm();
Html::footer();
Ejemplo n.º 13
0
<?php

include '../../../inc/includes.php';
Session::checkLoginUser();
if (empty($_REQUEST["id"])) {
    $_REQUEST["id"] = "";
}
$form = new PluginFormcreatorForm();
if (isset($_POST["add"])) {
    $form->check(-1, 'w', $_POST);
    $newID = $form->add($_POST);
    $newTarget = $form->createDefaultTarget($newID);
    $newSection = $form->createDefaultSection($newID, $newTarget);
    Html::redirect($CFG_GLPI["root_doc"] . "/plugins/formcreator/front/form.form.php?id=" . $newID);
} else {
    if (isset($_POST["delete"])) {
        $form->check($_POST["id"], 'd');
        $form->delete($_POST);
        $formID = $_POST["id"];
        //suppresion question
        $question = new PluginFormcreatorQuestion();
        $listQuestion = $question->find("plugin_formcreator_forms_id = '{$formID}'");
        foreach ($listQuestion as $question_id => $values) {
            $question->delete($values);
        }
        //suppresion section
        $section = new PluginFormcreatorSection();
        $listSection = $section->find("plugin_formcreator_forms_id = '{$formID}'");
        foreach ($listSection as $section_id => $values) {
            $section->delete($values);
        }
Ejemplo n.º 14
0
               <?php 
echo _n('LDAP directory', 'LDAP directories', 1);
?>
            </label>
         </td>
         <td>
            <div id="dropdown_values_field">
               <?php 
$optgroup = Dropdown::getStandardDropdownItemTypes();
array_unshift($optgroup, '---');
Dropdown::showFromArray('dropdown_values', $optgroup, array('value' => $question->fields['values'], 'rand' => $rand, 'on_change' => 'change_dropdown();'));
?>
            </div>
            <div id="glpi_objects_field">
               <?php 
$optgroup = array(__("Assets") => PluginFormcreatorForm::ArrayListOfItemtypes(), __("Assistance") => array('Ticket' => _n("Ticket", "Tickets", 2), 'Problem' => _n("Problem", "Problems", 2), 'TicketRecurrent' => __("Recurrent tickets")), __("Management") => array('Budget' => _n("Budget", "Budgets", 2), 'Supplier' => _n("Supplier", "Suppliers", 2), 'Contact' => _n("Contact", "Contacts", 2), 'Contract' => _n("Contract", "Contracts", 2), 'Document' => _n("Document", "Documents", 2)), __("Tools") => array('Notes' => __("Notes"), 'RSSFeed' => __("RSS feed")), __("Administration") => array('User' => _n("User", "Users", 2), 'Group' => _n("Group", "Groups", 2), 'Entity' => _n("Entity", "Entities", 2), 'Profile' => _n("Profile", "Profiles", 2)));
array_unshift($optgroup, '---');
Dropdown::showFromArray('glpi_objects', $optgroup, array('value' => $question->fields['values'], 'rand' => $rand, 'on_change' => 'change_glpi_objects();'));
?>
            </div>
            <div id="glpi_ldap_field">
            <?php 
$ldap_values = json_decode(plugin_formcreator_decode($question->fields['values']));
Dropdown::show('AuthLDAP', array('name' => 'ldap_auth', 'rand' => $rand, 'value' => isset($ldap_values->ldap_auth) ? $ldap_values->ldap_auth : '', 'on_change' => 'change_LDAP(this)'));
?>
            </div>
         </td>
      </tr>

      <tr class="line0" id="required_tr">
         <td>
Ejemplo n.º 15
0
<?php

include '../../../inc/includes.php';
$plugin = new Plugin();
if (!$plugin->isInstalled('formcreator') || !$plugin->isActivated('formcreator')) {
    Html::displayNotFoundError();
}
Session::checkLoginUser();
if ($_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') {
    Html::helpHeader(__('Form list', 'formcreator'), $_SERVER['PHP_SELF']);
} else {
    Html::header(__('Form list', 'formcreator'), $_SERVER['PHP_SELF'], 'plugins', 'formcreator', 'options');
}
$form = new PluginFormcreatorForm();
$form->showList();
Html::footer();
Ejemplo n.º 16
0
<?php

include "../../../inc/includes.php";
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator") && isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
    $form = new PluginFormcreatorForm();
    if ($form->getFromDB((int) $_REQUEST['id'])) {
        if ($form->fields['access_rights'] != PluginFormcreatorForm::ACCESS_PUBLIC) {
            Session::checkLoginUser();
        }
        if ($form->fields['access_rights'] == PluginFormcreatorForm::ACCESS_RESTRICTED) {
            $table = getTableForItemType('PluginFormcreatorFormprofiles');
            $query = "SELECT *\n                   FROM {$table}\n                   WHERE plugin_formcreator_profiles_id = {$_SESSION['glpiactiveprofile']['id']}\n                   AND plugin_formcreator_forms_id = {$form->fields['id']}";
            $result = $DB->query($query);
            if ($DB->numrows($result) == 0) {
                Html::displayRightError();
                exit;
            }
        }
        if ($form->fields['access_rights'] == PluginFormcreatorForm::ACCESS_PUBLIC && !isset($_SESSION['glpiID'])) {
            // If user is not authenticated, create temporary user
            if (!isset($_SESSION['glpiname'])) {
                $_SESSION['formcreator_forms_id'] = $form->fields['id'];
                $_SESSION['glpiname'] = 'formcreator_temp_user';
                $_SESSION['valid_id'] = session_id();
                $_SESSION['glpiactiveentities'] = $form->fields['entities_id'];
                $subentities = getSonsOf('glpi_entities', $form->fields['entities_id']);
                $_SESSION['glpiactiveentities_string'] = !empty($subentities) ? "'" . implode("', '", $subentities) . "'" : "'" . $form->fields['entities_id'] . "'";
            }
        }
Ejemplo n.º 17
0
 static function updateTicketFromForm($idform, $idticket)
 {
     global $DB;
     $datas = array();
     $templates_id = PluginFormcreatorForm::getTemplateTicketFromForm($idform);
     $ttp = new TicketTemplatePredefinedField();
     $predefined_fields = $ttp->getPredefinedFields($templates_id, true);
     $Ticket = new Ticket();
     $listaObjetos = $Ticket->find("id = '{$idticket}'");
     //$listaobjetos es un array que contiene, por cada ticket que comple la condición del find, un array con los campos del ticket
     $clave = array_keys($listaObjetos);
     if (isset($clave[0])) {
         if (isset($listaObjetos[$clave[0]])) {
             $datas = $listaObjetos[$clave[0]];
             unset($datas['urgency']);
             //
             unset($datas['priority']);
             //
             unset($datas['type']);
             //
             unset($datas['itilcategories_id']);
             //
             unset($datas['slas_id']);
             //
             $datas = array_merge($datas, $predefined_fields);
             $Ticket->update($datas);
         }
     }
 }
Ejemplo n.º 18
0
 public function saveAnswers($datas)
 {
     $form = new PluginFormcreatorForm();
     $form->getFromDB($datas['formcreator_form']);
     $query = "SELECT q.`id`, q.`fieldtype`, q.`name`\n                FROM glpi_plugin_formcreator_questions q\n                LEFT JOIN glpi_plugin_formcreator_sections s ON s.`id` = q.`plugin_formcreator_sections_id`\n                WHERE s.`plugin_formcreator_forms_id` = {$datas['formcreator_form']}";
     $result = $GLOBALS['DB']->query($query);
     // Update form answers
     if (isset($_POST['save_formanswer'])) {
         $status = $_POST['status'];
         $this->update(array('id' => (int) $datas['id'], 'status' => $status, 'comment' => isset($_POST['comment']) ? $_POST['comment'] : 'NULL'));
         // Update questions answers
         if ($status == 'waiting') {
             while ($question = $GLOBALS['DB']->fetch_array($result)) {
                 if ($question['fieldtype'] != 'file') {
                     $answer = new PluginFormcreatorAnswer();
                     $found = $answer->find('`plugin_formcreator_formanwers_id` = ' . (int) $datas['id'] . '
                                       AND `plugin_formcreator_question_id` = ' . $question['id']);
                     $found = array_shift($found);
                     $data_value = $datas['formcreator_field_' . $question['id']];
                     if (isset($data_value)) {
                         if (is_array($data_value)) {
                             foreach ($data_value as $key => $value) {
                                 $data_value[$key] = $value;
                             }
                             $answer_value = json_encode($data_value);
                         } else {
                             $answer_value = $data_value;
                         }
                     } else {
                         $answer_value = '';
                     }
                     $answer->update(array('id' => $found['id'], 'answer' => $answer_value));
                 } elseif (isset($_FILES['formcreator_field_' . $question['id']]['tmp_name']) && is_file($_FILES['formcreator_field_' . $question['id']]['tmp_name'])) {
                     $doc = new Document();
                     $answer = new PluginFormcreatorAnswer();
                     $found = $answer->find('`plugin_formcreator_formanwers_id` = ' . (int) $datas['id'] . '
                                       AND `plugin_formcreator_question_id` = ' . $question['id']);
                     $found = array_shift($found);
                     $file_datas = array();
                     $file_datas["name"] = $form->fields['name'] . ' - ' . $question['name'];
                     $file_datas["entities_id"] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id'];
                     $file_datas["is_recursive"] = $form->fields['is_recursive'];
                     Document::uploadDocument($file_datas, $_FILES['formcreator_field_' . $question['id']]);
                     if ($docID = $doc->add($file_datas)) {
                         $table = getTableForItemType('Document');
                         $filename = $_FILES['formcreator_field_' . $question['id']]['name'];
                         $query = "UPDATE {$table} SET filename = '" . $filename . "' WHERE id = " . $docID;
                         $GLOBALS['DB']->query($query);
                         $docItem = new Document_Item();
                         $docItemId = $docItem->add(array('documents_id' => $docID, 'itemtype' => __CLASS__, 'items_id' => (int) $datas['id']));
                         $answer->update(array('id' => $found['id'], 'answer' => $docID));
                     }
                 }
             }
         }
         // Create new form answer object
     } else {
         // Does the form need to be validate ?
         if ($form->fields['validation_required']) {
             $status = 'waiting';
         } else {
             $status = 'accepted';
         }
         $id = $this->add(array('entities_id' => isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id'], 'is_recursive' => $form->fields['is_recursive'], 'plugin_formcreator_forms_id' => $datas['formcreator_form'], 'requester_id' => isset($_SESSION['glpiID']) ? $_SESSION['glpiID'] : 0, 'validator_id' => isset($datas['formcreator_validator']) ? $datas['formcreator_validator'] : 0, 'status' => $status, 'request_date' => date('Y-m-d H:i:s')));
         // Save questions answers
         while ($question = $GLOBALS['DB']->fetch_assoc($result)) {
             // If the answer is set, check if it is an array (then implode id).
             if (isset($datas[$question['id']])) {
                 $question_answer = $datas[$question['id']];
                 if (is_array(json_decode($question_answer))) {
                     $question_answer = json_decode($question_answer);
                     foreach ($question_answer as $key => $value) {
                         $question_answer[$key] = $value;
                     }
                     $question_answer = json_encode($question_answer);
                 } else {
                     $question_answer = $question_answer;
                 }
             } else {
                 $question_answer = '';
             }
             $answer = new PluginFormcreatorAnswer();
             $answerID = $answer->add(array('plugin_formcreator_formanwers_id' => $id, 'plugin_formcreator_question_id' => $question['id'], 'answer' => $question_answer));
             // If the question is a file field, save the file as a document
             if ($question['fieldtype'] == 'file' && isset($_FILES['formcreator_field_' . $question['id']]['tmp_name']) && is_file($_FILES['formcreator_field_' . $question['id']]['tmp_name'])) {
                 $doc = new Document();
                 $file_datas = array();
                 $file_datas["name"] = $form->fields['name'] . ' - ' . $question['name'];
                 $file_datas["entities_id"] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id'];
                 $file_datas["is_recursive"] = $form->fields['is_recursive'];
                 Document::uploadDocument($file_datas, $_FILES['formcreator_field_' . $question['id']]);
                 if ($docID = $doc->add($file_datas)) {
                     $table = getTableForItemType('Document');
                     $filename = $_FILES['formcreator_field_' . $question['id']]['name'];
                     $query = "UPDATE {$table} SET filename = '" . $filename . "' WHERE id = " . $docID;
                     $GLOBALS['DB']->query($query);
                     $docItem = new Document_Item();
                     $docItemId = $docItem->add(array('documents_id' => $docID, 'itemtype' => __CLASS__, 'items_id' => $id));
                     $answer->update(array('id' => $answerID, 'answer' => $docID));
                 }
             }
         }
     }
     NotificationEvent::raiseEvent('plugin_formcreator_form_created', $this);
     if ($form->fields['validation_required'] || $status == 'accepted') {
         switch ($status) {
             case 'waiting':
                 // Notify the validator
                 NotificationEvent::raiseEvent('plugin_formcreator_need_validation', $this);
                 break;
             case 'refused':
                 // Notify the requester
                 NotificationEvent::raiseEvent('plugin_formcreator_refused', $this);
                 break;
             case 'accepted':
                 // Notify the requester
                 if (!$this->generateTarget()) {
                     Session::addMessageAfterRedirect(__('Cannot generate targets!', 'formcreator'), true, ERROR);
                     $this->update(array('id' => $this->getID(), 'status' => 'waiting'));
                 }
                 NotificationEvent::raiseEvent('plugin_formcreator_accepted', $this);
                 return false;
                 break;
         }
     }
     Session::addMessageAfterRedirect(__('The form have been successfully saved!', 'formcreator'), true, INFO);
 }
Ejemplo n.º 19
0
<?php

include "../../../inc/includes.php";
// Check if plugin is activated...
$plugin = new Plugin();
if ($plugin->isActivated("formcreator")) {
    $form = new PluginFormcreatorForm();
    // Add a new Form
    if (isset($_POST["add"])) {
        $form->check(-1, 'w', $_POST);
        $newID = $form->add($_POST);
        // $newTarget = $form->createDefaultTarget($newID);
        // $newSection = $form->createDefaultSection($newID,$newTarget);
        Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $newID);
        // Edit an existinf form
    } elseif (isset($_POST["update"])) {
        $form->check($_POST['id'], 'w');
        $form->update($_POST);
        Html::back();
        // Delete a form (is_deleted = true)
    } elseif (isset($_POST["delete"])) {
        $form->check($_POST['id'], 'd');
        $form->delete($_POST);
        $form->redirectToList();
        // Restore a deleteted form (is_deleted = false)
    } elseif (isset($_POST["restore"])) {
        $form->check($_POST['id'], 'd');
        $form->restore($_POST);
        $form->redirectToList();
        // Delete defenitively a form from DB and all its datas
    } elseif (isset($_POST["purge"])) {