Пример #1
0
 /**
  * @param $model  PluginDatainjectionModel object
  **/
 static function showFormMappings(PluginDatainjectionModel $model)
 {
     global $CFG_GLPI;
     $canedit = $model->can($model->fields['id'], UPDATE);
     if (isset($_SESSION['datainjection']['lines'])) {
         $lines = unserialize($_SESSION['datainjection']['lines']);
     } else {
         $lines = array();
     }
     echo "<form method='post' name=form action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     //Display link to the preview popup
     if (isset($_SESSION['datainjection']['lines']) && !empty($lines)) {
         $nblines = $_SESSION['datainjection']['nblines'];
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><td class='center'>";
         $url = $CFG_GLPI["root_doc"] . "/plugins/datainjection/front/popup.php?popup=preview&amp;models_id=" . $model->getID();
         echo "<a href=#  onClick=\"var w = window.open('{$url}' , 'glpipopup', " . "'height=400, width=600, top=100, left=100, scrollbars=yes' );w.focus();\"/>";
         echo __('See the file', 'datainjection') . "</a>";
         echo "</td></tr>";
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th>" . __('Header of the file', 'datainjection') . "</th>";
     echo "<th>" . __('Tables', 'datainjection') . "</th>";
     echo "<th>" . _n('Field', 'Fields', 2) . "</th>";
     echo "<th>" . __('Link field', 'datainjection') . "</th>";
     echo "</tr>";
     $model->loadMappings();
     foreach ($model->getMappings() as $mapping) {
         $mapping->fields = Toolbox::stripslashes_deep($mapping->fields);
         $mappings_id = $mapping->getID();
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>" . $mapping->fields['name'] . "</td>";
         echo "<td class='center'>";
         $options = array('primary_type' => $model->fields['itemtype']);
         PluginDatainjectionInjectionType::dropdownLinkedTypes($mapping, $options);
         echo "</td>";
         echo "<td class='center'><span id='span_field_{$mappings_id}'>";
         echo "</span></td>";
         echo "<td class='center'><span id='span_mandatory_{$mappings_id}'></span></td>";
     }
     if ($canedit) {
         echo "<tr> <td class='tab_bg_2 center' colspan='4'>";
         echo "<input type='hidden' name='models_id' value='" . $model->fields['id'] . "'>";
         echo "<input type='submit' name='update' value='" . _sx('button', 'Save') . "' class='submit'>";
         echo "</td></tr>";
     }
     echo "</table>";
     Html::closeForm();
 }
Пример #2
0
 /**
  *
  * Display additional information form from Model form
  * @param PluginDatainjectionModel $model
  */
 static function showFormInfos(PluginDatainjectionModel $model)
 {
     $canedit = $model->can($model->fields['id'], UPDATE);
     self::showAddInfo($model, $canedit);
     $model->loadInfos();
     $nb = count($model->getInfos());
     if ($nb > 0) {
         echo "<form method='post' name='info_form' id='info_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr>";
         if ($canedit) {
             echo "<th>&nbsp;</th>";
         }
         echo "<th>" . __('Tables', 'datainjection') . "</th>";
         echo "<th>" . __('Fields', 'datainjection') . "</th>";
         echo "<th>" . __('Mandatory information', 'datainjection') . "</th>";
         echo "</tr>";
         foreach ($model->getInfos() as $info) {
             $info->fields = Toolbox::stripslashes_deep($info->fields);
             $infos_id = $info->fields['id'];
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 $sel = "";
                 if (isset($_GET["select"]) && $_GET["select"] == "all") {
                     $sel = "checked";
                 }
                 echo "<input type='checkbox' name='item[" . $infos_id . "]' value='1' {$sel}>";
                 echo "</td>";
             }
             echo "<td class='center'>";
             $rand = PluginDatainjectionInjectionType::dropdownLinkedTypes($info, array('primary_type' => $model->fields['itemtype']));
             echo "</td>";
             echo "<td class='center'><span id='span_field_{$infos_id}'></span></td>";
             echo "<td class='center'><span id='span_mandatory_{$infos_id}'></span></td></tr>";
         }
         if ($canedit) {
             echo "<tr>";
             echo "<td class='tab_bg_2 center' colspan='4'>";
             echo "<input type='hidden' name='models_id' value='" . $model->fields['id'] . "'>";
             echo "<input type='submit' name='update' value='" . _sx('button', 'Save') . "' class='submit'>";
             echo "</td></tr>";
             Html::openArrowMassives("info_form", true);
             Html::closeArrowMassives(array('delete' => __('Delete permanently')));
         }
         echo "</table>";
         Html::closeForm();
     }
 }
Пример #3
0
 static function methodInject($params, $protocol)
 {
     if (isset($params['help'])) {
         return array('uri' => 'string,mandatory', 'base64' => 'string,optional', 'additional' => 'array,optional', 'models_id' => 'integer, mandatory', 'entities_id' => 'integer,mandatory', 'mandatory' => 'array,optional', 'uri' => 'uri,mandatory', 'help' => 'bool,optional');
     }
     $model = new PluginDatainjectionModel();
     //-----------------------------------------------------------------
     //-------------------------- Check parameters ---------------------
     //-----------------------------------------------------------------
     if (!isset($_SESSION['glpiID'])) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     if (!isset($params['uri']) && !isset($params['base64'])) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'uri or base64');
     }
     if (!isset($params['models_id'])) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, 'models_id');
     }
     if (!$model->getFromDB($params['models_id'])) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTFOUND, __('Model unknown', 'datainjection'));
     }
     if (!$model->can($params['models_id'], 'r')) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, __('You cannot access this model', 'datainjection'));
     }
     if ($model->fields['step'] < PluginDatainjectionModel::READY_TO_USE_STEP) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, __('You cannot access this model', 'datainjection'));
     }
     //Check entity
     if (!isset($params['entities_id'])) {
         return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, 'entities_id');
     }
     $entities_id = $params['entities_id'];
     if ($entities_id > 0) {
         $entity = new Entity();
         if (!$entity->getFromDB($entities_id)) {
             return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTFOUND, __('Entity unknown', 'datainjection'));
         }
         if (!Session::haveAccessToEntity($entities_id)) {
             return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, __('You cannot access this entity', 'datainjection'));
         }
     }
     //Mandatory fields
     $additional_infos = array();
     if (isset($params['additional']) && is_array($params['additional'])) {
         $additional_infos = $params['additional'];
     }
     //Upload CSV file
     $document_name = basename($params['uri']);
     $filename = tempnam(PLUGIN_DATAINJECTION_UPLOAD_DIR, 'PWS');
     $response = PluginWebservicesMethodCommon::uploadDocument($params, $protocol, $filename, $document_name);
     if (PluginWebservicesMethodCommon::isError($protocol, $response)) {
         return $response;
     }
     //Uploade successful : now perform import !
     $options = array('file_encoding' => PluginDatainjectionBackend::ENCODING_AUTO, 'webservice' => true, 'original_filename' => $params['uri'], 'unique_filename' => $filename, 'mode' => PluginDatainjectionModel::PROCESS, 'delete_file' => false, 'protocol' => $protocol);
     //The Webservice protocol used
     $results = array();
     $response = $model->processUploadedFile($options);
     if (!PluginWebservicesMethodCommon::isError($protocol, $response)) {
         $engine = new PluginDatainjectionEngine($model, $additional_infos, $params['entities_id']);
         //Remove first line if header is present
         $first = true;
         foreach ($model->injectionData->getDatas() as $id => $data) {
             if ($first && $model->getSpecificModel()->isHeaderPresent()) {
                 $first = false;
             } else {
                 $results[] = $engine->injectLine($data[0], $id);
             }
         }
         $model->cleanData();
         return $results;
     }
     return $response;
 }
Пример #4
0
 @copyright Copyright (c) 2010-2013 Datainjection plugin team
 @license   GPLv2+
            http://www.gnu.org/licenses/gpl.txt
 @link      https://forge.indepnet.net/projects/datainjection
 @link      http://www.glpi-project.org/
 @since     2009
 ---------------------------------------------------------------------- */
include '../../../inc/includes.php';
Html::header(__('File injection', 'datainjection'), $_SERVER["PHP_SELF"], "tools", "plugindatainjectionmenu", "client");
if (isset($_SESSION['datainjection']['go'])) {
    $model = unserialize($_SESSION['datainjection']['currentmodel']);
    PluginDatainjectionClientInjection::showInjectionForm($model, $_SESSION['glpiactive_entity']);
} else {
    if (isset($_POST['upload'])) {
        $model = new PluginDatainjectionModel();
        $model->can($_POST['id'], READ);
        $_SESSION['datainjection']['infos'] = isset($_POST['info']) ? $_POST['info'] : array();
        //If additional informations provided : check if mandatory infos are present
        if (!$model->checkMandatoryFields($_SESSION['datainjection']['infos'])) {
            Session::addMessageAfterRedirect(__('One mandatory field is not filled', 'datainjection'), true, ERROR, true);
        } else {
            if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] && $_FILES['filename']['tmp_name'] && !$_FILES['filename']['error'] && $_FILES['filename']['size']) {
                //Read file using automatic encoding detection, and do not delete file once readed
                $options = array('file_encoding' => $_POST['file_encoding'], 'mode' => PluginDatainjectionModel::PROCESS, 'delete_file' => false);
                $response = $model->processUploadedFile($options);
                $model->cleanData();
                if ($response) {
                    //File uploaded successfully and matches the given model : switch to the import tab
                    $_SESSION['datainjection']['file_name'] = $_FILES['filename']['name'];
                    $_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_PROCESS;
                    //Store model in session for injection
Пример #5
0
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with datainjection. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
 @package   datainjection
 @author    the datainjection plugin team
 @copyright Copyright (c) 2010-2013 Datainjection plugin team
 @license   GPLv2+
            http://www.gnu.org/licenses/gpl.txt
 @link      https://forge.indepnet.net/projects/datainjection
 @link      http://www.glpi-project.org/
 @since     2009
 ---------------------------------------------------------------------- */
// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "dropdownSelectModel.php")) {
    include '../../../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
Session::checkCentralAccess();
if (isset($_SESSION['datainjection']['models_id']) && $_SESSION['datainjection']['models_id'] != $_POST['models_id']) {
    PluginDatainjectionModel::cleanSessionVariables();
}
$_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_UPLOAD;
$model = new PluginDatainjectionModel();
if ($_POST['models_id'] > 0 && $model->can($_POST['models_id'], READ)) {
    PluginDatainjectionInfo::showAdditionalInformationsForm($model);
}